我的代碼不工作,它總是顯示上述異常。 但我總是可以看到正在生成的tmp文件。org.apache.poi.openxml4j.exceptions.InvalidOperationException:無法打開指定的文件
這裏是代碼,可以有人請建議的內容:
FileInputStream fis =null;
try{
fis= new FileInputStream(new File("/home/amar/Desktop/new/abc.xls"));
Workbook wb = new org.apache.poi.xssf.usermodel.XSSFWorkbook(fis);
int numOfSheets = wb.getNumberOfSheets();
System.out.println("bhargo num of sheets is " + numOfSheets);
for(int i=0; i<numOfSheets; i++){
org.apache.poi.ss.usermodel.Sheet sheet = wb.getSheetAt(i);
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext())
{
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = (Cell) cellIterator.next();
if (cell.getCellType() == cell.CELL_TYPE_STRING) {
System.out.println("bhargo cell value is " + cell.getStringCellValue().trim());
}
}
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
System.out.println("bhargo, closing the stream");
try {
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
是,這正是我所認識和使用WorkbookFactory代替。 – 2014-09-24 11:33:45
感謝分享 – 2014-09-24 11:34:08
是'wb = new XSSFWorkbook(spreadSheetFileName);'同樣好,其中'spreadSheetFileName'是一個'String'嗎? – mbmast 2016-05-21 22:37:36