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

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

问题描述

大家好我目前使用的3.9 POI库,Excel文件的工作。我知道 getLastRowNum()函数,该函数返回一个Excel文件行数的。

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.

唯一的问题是 getLastRowNum()返回一个数字,从0开始计数。

The only problem is getLastRowNum() returns a number with the count starting from 0.

因此​​,如果一个Excel文件使用第3行, getLastRowNum()返回2。
如果一个Excel文件刚刚1排, getLastRowNum()返回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.

当Excel文件是完全空的,会出现问题。 getLastRowNum()仍返回0,所以我不能确定是否Excel文件有1行的数据,或者如果它是空的。

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.

所以,我怎么可以检测一个Excel文件为空或不?

So how can I detect if an Excel file is empty or not ?

推荐答案

尝试<一个href=\"http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFSheet.html#getPhysicalNumberOfRows%28%29\">Sheet.getPhysicalNumberOfRows()

这篇关于如何获得行计数使用POI库中的Excel文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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