一、使用try自动关闭流报错
1.附上自己自动关闭流的代码 try (InputStream is = new FileInputStream("D:\\lx-studyResources\\example.xlsx");OutputStream out = new FileOutputStream("D:\\lx-studyResources\\example.xlsx")){ XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is); //取出第一个工作表 sheet = xssfWorkbook.getSheetAt(0); //设置字体 XSSFFont font = xssfWorkbook.createFont(); font.setColor(Font.COLOR_RED); //设置样式 XSSFCellStyle style = xssfWorkbook.createCellStyle(); style.setFont(font); String value = sheet.getRow(0).getCell(0).getRawValue(); sheet.getRow(0).getCell(0).setCellStyle(style); sheet.getRow(0).getCell(0).setCellValue("lx_pb"); xssfWorkbook.write(out); }catch (Exception e){ e.printStackTrace(); }
2.报错的截图
我的Excel中明明不是空,为啥还会报这个错呢?