错误Sheet index (0) is out of range (0..-1)

之前使用Java POI操作Excel 发生错误:错误Sheet index (0) is out of range (0…-1);窗口报错如下:
错误Sheet index (0) is out of range (0..-1)_第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 );

你可能感兴趣的:(TC)