0

I need to modify the value of a column First I look for the column by its name, getting the index. I would like to see how I can modify the value of that column based on its ID, or on the contrary, on its range

public static class EpPlusExtensionMethods
{ 
    public static int GetColumnByName(this ExcelWorksheet ws, string columnName)
    {
        if (ws == null) throw new ArgumentNullException(nameof(ws));
        return ws.Cells["1:1"].First(c => c.Value.ToString() == columnName).Start.Column;
    }
}

int columnId = ws.GetColumnByName("Birthdate"); 
ararb78
  • 1,137
  • 5
  • 19
  • 44
  • 1
    What do you mean `modify the value of a column`? Set all cells to the same value? Modify a specific cell? Besides, columns don't have names, they're identified by *letters*. What you check in your code are the contents of the first row. That's just a cell value, not a column name. What you retrieve is the index, not an ID – Panagiotis Kanavos May 11 '21 at 15:54
  • You can use `ws.Cells[rowIdx,colIdx]` to access specific cells by index and iterate over a row's or column's cells. – Panagiotis Kanavos May 11 '21 at 15:55
  • Ok, it's right! – ararb78 May 11 '21 at 16:56

0 Answers0