之前使用Java POI操作Excel 发生错误:错误Sheet index (0) is out of range (0…-1);窗口报错如下:
检测异常代码如下:catch (Exception e) { e.printStackTrace(); monitor.done();关掉进度条,防止卡死; MessageBox.post(AIFDesktop.getActiveDesktop(), "程序异常:" + e.getLocalizedMessage(), "错误", MessageBox.ERROR); }
问题代码:
FileInputStream fileInputStream = new FileInputStream(templateFile);
XSSFWorkbook workbook = new XSSFWorkbook();
更正代码:
FileInputStream fileInputStream = new FileInputStream(templateFile);
XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream );