发现最后一排的一个Excel US preadsheet [英] Finding the last row in an Excel spreadsheet

查看:159
本文介绍了发现最后一排的一个Excel US preadsheet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用Apache的POI for Java来找到一个excel US preadsheet最后一行的索引。

I'm trying to find the index of the last row in an excel spreadsheet using Apache's POI for Java.

我想这应该是可能的 getLastRowNum() getPhysicalNumberOfRows(),但他们似乎并没有做给出正确的结果。例如,我有一个线S preadsheet这两个函数返回1140值另有两线S preadsheets得到1162的值。

I thought this should be possible with getLastRowNum() or getPhysicalNumberOfRows() but they don't seem to give the right results. For example, I have a one line spreadsheet and these two functions return a value of 1140. Another two line spreadsheets gets a value of 1162.

另一个问题是,我不能只是看的第一个空行,因为它可能有有效数据的行之间的空行。

The other problem is that I cannot just look for the first empty row, since it may be possible to have empty rows between rows of valid data.

那么,有没有办法找到最后一排的指数?我想我可以做它没有数据之间的空行的要求,但我希望的是更好的解决方案。

So is there a way to find the index of the last row? I suppose I could make it a requirement to not have empty rows between data, but I was hoping for a better solution.

编辑:对于使用迭代器没有帮助的记录。它只是遍历的一千一百六十二分之一千一百四十零应该行。

For the record using an iterator didn't help. It just iterated over the 1140/1162 supposed rows.

推荐答案

我用得到预期的输出POI-3.6-20091214和 TEST.XLS 有两个空行其次是三个被占领行:

I get the expected output using poi-3.6-20091214 and a test.xls having two empty rows followed by three occupied rows:

InputStream myxls = new FileInputStream("test.xls");
Workbook book = new HSSFWorkbook(myxls);
Sheet sheet = book.getSheetAt(0);
System.out.println(sheet.getLastRowNum());

输出: 4

这篇关于发现最后一排的一个Excel US preadsheet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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