how to get EPPlus OpenXML row count (c#)

前端 未结 5 1742
无人共我
无人共我 2021-01-17 09:49

I searched for it and found the link C# EPPlus OpenXML count rows

int iRowCount = currentWorksheet.Dimension.End.Row - currentWorksheet.Dimension.Start.Row;
         


        
5条回答
  •  一个人的身影
    2021-01-17 09:59

    Actual Answer to return the number of Rows and Columns of the UsedRange (the dimention) of a sheet is...

    int iColCnt = Worksheet.Dimension.End.Column
    int iRowCnt = Worksheet.Dimension.End.Row
    

    But you need to test if Worksheet.Dimension is null because for new worksheets or empty worksheets the Dimension property will be null.

    Also since the definition of "Empty" is something that is very specific to each case it would be hard to have a generic function like that. The only one that seems to make the most sense is all values are blank. But Blank and Nothing are really different in themselves. (EG a comment in a cell could be present and that could be considered enough for a row to not be considered blank in a specific case)

    See Peter Reisz answer for example of that style to find the end of your worksheet.

提交回复
热议问题