如何使用POI库在Excel文件中获取行数? [英] How to get row count in an Excel file using POI library?
问题描述
getLastRowNum()
函数,它返回一个Excel文件中的行数。 唯一的问题是 getLastRowNum()
返回一个数字,计数从0开始。
所以如果Excel文件使用前3行 getLastRowNum()
返回2.
如果Excel文件只有1行, getLastRowNum()
返回0。
当Excel文件完全为空时,会出现此问题。 getLastRowNum()
仍然返回0,所以我无法确定Excel文件是否有1行数据,或者是空的。
那么如何检测Excel文件是否为空?
尝试 Sheet.getPhysicalNumberOfRows()
Guys I'm currently using the POI 3.9 library to work with excel files. I know of the getLastRowNum()
function, which returns a number of rows in an Excel file.
The only problem is getLastRowNum()
returns a number with the count starting from 0.
So if an Excel file uses the first 3 rows, getLastRowNum()
returns 2.
If an Excel file has just 1 row, getLastRowNum()
returns 0.
The problem occurs when the Excel file is completely empty. getLastRowNum()
still returns 0, so I cannot determine if the Excel file has 1 row of data, or if its empty.
So how can I detect if an Excel file is empty or not ?
Try Sheet.getPhysicalNumberOfRows()
这篇关于如何使用POI库在Excel文件中获取行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!