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

后端 未结 9 629
执念已碎
执念已碎 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:24

    I would start with the UsedRange property and then for each Cell in the final Row of the UsedRange do Cell.End(xlUp). This should get you the final cell for each column, the cell which has the maximum row index is the last cell in your true used range.

    The UsedRange property can appear wrong because when cells are cleared but not deleted, the UsedRange property is not updated. To make the UsedRange property valid again simply select all the rows and columns after your last cell (so all the blank cells) and go edit->delete.

提交回复
热议问题