我想编辑一个使用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