POI追加内容至excel文件中
原excel:
![在这里插入图片描述](https://img-blog.csdnimg.cn/fff4aea9216c4baaa83e40739fffc947.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMxMTkyNTEx,size_16,color_FFFFFF,t_70)
代码:
InputStream stream = new FileInputStream("C:\\Users\\aa\\Downloads\\demoExcel.xlsx");
OPCPackage open = OPCPackage.open(stream);
XSSFWorkbook sheets = new XSSFWorkbook(open);
XSSFSheet sheet = sheets.getSheetAt(0);
sheet.getRow(0).createCell(3).setCellValue("sum");
sheet.getRow(1).createCell(3).setCellValue("11");
sheet.getRow(2).createCell(3).setCellValue("22");
sheet.getRow(3).createCell(3).setCellValue("33");
OutputStream out = new FileOutputStream("C:\\Users\\aa\\Downloads\\test.xlsx");
sheet.getWorkbook().write(out);
写入后的excel
思路大致如上,可自行对其进行优化