如何使用POI库在Excel文件中获取行数? [英] How to get row count in an Excel file using POI library?

查看:403
本文介绍了如何使用POI库在Excel文件中获取行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用POI 3.9库来处理excel文件。我知道 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屋!

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