读取多个Excel工作表 [英] Reading multiple excel sheet
本文介绍了读取多个Excel工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用foor循环阅读电子表格的表格.我想知道这是正确的阅读方式,尤其是Sheet Propety的使用[在代码中突出显示]:
I am trying to read the sheets of a spread sheet uisng a foor loop. I wanted to know is this the right way of reading especially the use of Sheet Propety [highlighted in the code] :
Cell[][] newcell=new Cell[200][200];
int newsheet = workbook1.getNumberOfSheets();
for (int q=1;q < newsheet;q++)
{
for(int p=0;p < sheet(q).getColumns();p++)
{
for(int p1=0;p1<sheet(q).getRows();p1++)
/*^^^^^^^^^*/
{
newcell[p][p1] = sheet(q).getCell(p, p1);
/*^^^^^^^^^*/
if(newcell[p][p1].equals(saved[j]))
{
System.out.print( newcell[p][0]);
}
}
}
}
是否可以将sheet()的属性用作sheet(q),因为它会抛出NullPointerException
?
Can I use the property of sheet() as sheet(q) because its throwing NullPointerException
?
推荐答案
处理POI中所有单元格的常用样式是:
The usual style for working with all the cells in POI is:
for(int sheetNum=0; sheetNum < wb.getNumberOfSheets(); sheetNum++) {
Sheet sheet = wb.getSheetAt(sheetNum);
for (Row row : sheet) {
for (Cell cell : row) {
// Do something here
}
}
}
也许将您的代码切换到更多类似的东西?
Maybe switch your code to something more like that?
这篇关于读取多个Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文