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

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

问题描述

伙计们,我目前正在使用 POI 3.9 库来处理 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 ?

推荐答案

尝试 Sheet.getPhysicalNumberOfRows()

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

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