C#: Getting the number of rows/columns with ExcelPackage

后端 未结 9 631
执念已碎
执念已碎 2021-02-03 18:59

I need to read and write data from an Excel spreadsheet. Is there a method to finding out how many rows/columns a certain worksheet has using ExcelPackage? I have the following

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-03 19:33

    I just did the following loop to solve the problem. It works fine only if you know how many columns there will be beforehand. Otherwise it would take another loop iteration.

    int totalCells = 0;
    int totalRows = -1;
    
    do
    {
         totalRows++;
    } while (worksheet.Cell(totalRows + 1, 1).Value != @"");
    totalCells = totalRows * 12;
    

提交回复
热议问题