Get the number of rows of data with SpreadSheetGear?

醉酒当歌 提交于 2019-12-01 14:57:39

问题


I've checked a few online resources, maybe I'm blind but I've as yet been unable to find an answer to this.

I'm uploading a file, converting it to a stream, feeding it into SpreadSheetGear. Now, I need to loop through every row and read the data (which is fine). Here is my code so far:

IWorkbook wb = Factory.GetWorkbookSet().Workbooks.OpenFromStream(file.InputStream);
IWorksheet ws = wb.ActiveWorksheet;
IRange cells = ws.Cells;

for (int i = 2; i <= cells.RowCount; i++)
{
    //Code for every row
    for (int x = 1; x <= cells.ColumnCount; x++)
    {
         //Code for every column
    }
}

Here is the problem: cells.RowCount is equal to 1048576 which is clearly the Excel upper limit on number of rows. Is there a call to SpreadSheetGear that returns the number of rows that have data? I cant use a fixed amount as the spreadsheet provided could have anything from 500 to 2,000 rows.

I understand SpreadSheetGear may not be that widely used but I thought I'd chance my arm here anyway.

Cheers!

Edit :

Before somebody says use a while loop, it's possible that a row can be empty so checking for null strings is a bit of a messy one.


回答1:


Answered my own question, always the way.

Anyway, eventually found IWorksheet.UsedRange which returns just the used cells.



来源:https://stackoverflow.com/questions/6509291/get-the-number-of-rows-of-data-with-spreadsheetgear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!