Apache POI行号 [英] Apache POI rows number
问题描述
我正在使用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屋!