我想編輯一個使用apache poi的excel表格, 我有一個有2行5列的工作表 如果第二行的第二個單元格爲空,那麼它應該添加第三行, 但我得到一個類沒有發現異常,雖然UpdateXLS存在於我的D驅動器。使用Apache poi編輯excel表格
下面是代碼:
public class New {
public static void main(String[] args){
try{
InputStream inp = new FileInputStream("D:\\UpdateXLS.xls");
//InputStream inp = new FileInputStream("workbook.xlsx");
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(2);
Cell cell = row.getCell(2);
if (cell == null)
cell = row.createCell(3);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue("a test");
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("UpdateXLS.xls");
wb.write(fileOut);
fileOut.close();
}
catch(Exception e){
e.printStackTrace();
}
}
我應該怎麼辦?
請包括堆棧跟蹤。 – 2014-10-20 12:02:14
java.io.FileNotFoundException:D:\ UpdateXLS.xls(系統找不到指定的文件) \t at java.io.FileInputStream.open(Native Method) \t at java.io.FileInputStream。(Unknown Source) \t at java.io.FileInputStream。 (來源不明) \t在com.New.main(New.java:17) –
ITI
2014-10-20 12:03:25