使用Java获取给定excel中特定行的列数 [英] get number of columns of a particular row in given excel using Java
本文介绍了使用Java获取给定excel中特定行的列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要Excel中特定行的列数。怎么可能?我使用POI API
I want the number of columns of a particular row in excel. How is that possible? I used POI API
但是我只能列数为7。
try
{
fileInputStream = new FileInputStream(file);
workbook = new HSSFWorkbook(fileInputStream);
Sheet sheet = workbook.getSheet("0");
int numberOfCells = 0;
Iterator rowIterator = sheet.rowIterator();
/**
* Escape the header row *
*/
if (rowIterator.hasNext())
{
Row headerRow = (Row) rowIterator.next();
//get the number of cells in the header row
numberOfCells = headerRow.getPhysicalNumberOfCells();
}
System.out.println("number of cells "+numberOfCells);
}
我想要特定行号的列数说10。
excel列不一样
I want the number of columns at a particular row number say 10 . The excel columns are not same
推荐答案
有两件事你可以做
使用
int noOfColumns = sh.getRow(0).getPhysicalNumberOfCells();
或
int noOfColumns = sh.getRow(0).getLastCellNum();
他们之间有一个很好的区别
There is a fine difference between them
- 选项1给出了实际填充内容的列的数量(如果第10列的第2列未填写,则将得到9)
- 选项2只是给你最后一列的索引。因此完成'getLastCellNum()'
这篇关于使用Java获取给定excel中特定行的列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文