获取带有S preadSheetGear数据行数? [英] Get the number of rows of data with SpreadSheetGear?

查看:487
本文介绍了获取带有S preadSheetGear数据行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经检查了几个网上的资源,也许我瞎了,但我目前还无法找到一个答案。

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

我在上传文件时,将其转换为一个流,喂养它进入S preadSheetGear。现在,我需要遍历每一行和读取数据(这是罚款)。这里是我的code迄今:

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
    }
}

下面的问题是:cells.RowCount等于 1048576 这显然是对行数Excel的上限。有没有向S preadSheetGear返回有数据行数的电话吗?我不能用一个固定的数额提供了可能有500到2000行什么在S preadsheet。

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.

我明白US preadSheetGear可能不那么广泛,但我想我的机会我的胳膊在这里反正。

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

干杯!

编辑:

在有人说使用whil​​e循环,它可能是一个行可为空,以便检查空字符串是有点凌乱之一。

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.

不管怎样,最终找到 IWorksheet.UsedRange 返回刚刚使用的细胞。

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

这篇关于获取带有S preadSheetGear数据行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆