Apache POI 行数 [英] Apache POI rows number

查看:32
本文介绍了Apache POI 行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Apache POI java 并想获取非空行的总数.我成功地处理了一整行及其所有列.现在我假设我得到了一个多行而不是单行的 Excel 工作表......那么如何去做呢?我正在考虑获取总行数(int n)然后循环直到 i<=n 但不确定.

I am using Apache POI java and want to get the total number of rows which are not empty. I successfully processed a whole row with all its columns. Now I am assuming that I get an excel sheet with multiple rows and not a single row...so how to go about that? I was thinking of getting total number of rows (int n) and then loop until i<=n but not sure.

欢迎提出建议:)

注意:Apache POI 版本为 3.8.我不处理 Xlsx 格式...只处理 xls.

Note: Apache POI version is 3.8. I am not dealing with Xlsx format...only xls.

是的,我试过这个代码,但得到了 20 的回报......这是不可能的,因为我只有 5 行

Yes I tried this code but got 20 in return....which is not possible given I have only 5 rows

FileInputStream fileInputStream = new FileInputStream("COD.xls");
            HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
            HSSFSheet worksheet = workbook.getSheet("COD");
            HSSFRow row1 = worksheet.getRow(3);
            Iterator rows = worksheet.rowIterator(); 
            int noOfRows = 0;
            while( rows.hasNext() ) {
                HSSFRow row = (HSSFRow) rows.next();
                noOfRows++;                
            }
            System.out.println("Number of Rows: " + noOfRows);

推荐答案

for (int i = 0; i <= sheet.getLastRowNum(); i++) {
    if ((tempRow = sheet.getRow(i)) != null) {
           //Your Code Here
    }
}

这篇关于Apache POI 行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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