使用 SpreadSheetGear 获取数据行数?
我查了一些网上资源,也许我是瞎子,但我还无法找到答案。
我正在上传一个文件,将其转换为流,然后将其输入 SpreadSheetGear。现在,我需要循环遍历每一行并读取数据(这很好)。到目前为止,这是我的代码:
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 的行数上限。是否有对 SpreadSheetGear 的调用返回包含数据的行数?我无法使用固定金额,因为提供的电子表格可能有 500 到 2,000 行。
我知道 SpreadSheetGear 可能没有那么广泛使用,但我想无论如何我都会在这里碰碰运气。
干杯!
编辑:
在有人说使用 while 循环之前,行可能为空,因此检查空字符串有点混乱。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答我自己的问题,总是这样。
无论如何,最终发现
IWorksheet.UsedRange
它只返回使用的单元格。Answered my own question, always the way.
Anyway, eventually found
IWorksheet.UsedRange
which returns just the used cells.