Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: Using foreach to deal with Excel rows and skip the 1st row as header

$
0
0
You can indeed use Rows() function without any arguments. I tried it and it works
There are 3 overloads
  • IXLRangeRows Rows(Func<IXLRangeRow, bool> predicate = null); // but this could be empty!
  • IXLRangeRows Rows(string rows); // e.g. Rows("4:5"), Rows("7:8,10:11"), Rows("13")
  • IXLRangeRows Rows(int firstRow, int lastRow);
    string test1 = row.Field("Name").GetString();  // <--- Doesn't work
Note - this will only work if one of the columns has the heading of "Name"
Do any of your columns have the heading of "Name"?
    string test2 = row.Cell(1).GetString();             // <--- Works but doesn't skip header row
Of course not. You told it to iterate through all the rows!
To skip the first row do
    foreach(var row in table.Rows(table.FirstRow+1,table.LastRow))

Viewing all articles
Browse latest Browse all 1877

Trending Articles