获得给定的Excel中的一个特定行的列数 [英] get number of columns of a particular row in given excel
本文介绍了获得给定的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。
but i could get only columns count to 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();
有他们之间的罚款区别
- 选项1给出了没有这实际上是充满了内容(如果10列的第2列不填充你会得到9) 列
- 选项2只是给你最后一列的索引。因此,做'getLastCellNum()
这篇关于获得给定的Excel中的一个特定行的列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文