开发者

Get the number of rows of data with SpreadSheetGear?

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.RowCo开发者_运维知识库unt; 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.


Answered my own question, always the way.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜