如何使用 JAVA 中的 apache POI 在 excel 中的单元格中写入?
How to write in cell in excel using apache POI in JAVA?
如何将 excel 文件写入特定 cell.I 有一种方法可以接受我必须写入的文件位置和行号。
我尝试读取文件然后创建一个单元格并将值设置到其中,但是当我查看它时单元格仍然是空白的。
public void writeInExcelRowCell(String file , int rowNum) throws Exception {
FileInputStream excelFile = new FileInputStream(new File(file));
Workbook workbook = new XSSFWorkbook(excelFile);
Sheet sheet = workbook.getSheetAt(0);
sheet.getRow(rowNum).createCell(2).setCellValue("DONE");
sheet.getRow(rowNum).createCell(3).setCellValue("PENDING");
workbook.close();
}
你做的是对的,但是忘了写你的修改。
您需要打开一个输出流来写入这些更改。
FileOutputStream outputStream = new FileOutputStream("yourfile");
workbook.write(outputStream);
workbook.close();
outputStream.close();
希望这有效!!
如何将 excel 文件写入特定 cell.I 有一种方法可以接受我必须写入的文件位置和行号。
我尝试读取文件然后创建一个单元格并将值设置到其中,但是当我查看它时单元格仍然是空白的。
public void writeInExcelRowCell(String file , int rowNum) throws Exception {
FileInputStream excelFile = new FileInputStream(new File(file));
Workbook workbook = new XSSFWorkbook(excelFile);
Sheet sheet = workbook.getSheetAt(0);
sheet.getRow(rowNum).createCell(2).setCellValue("DONE");
sheet.getRow(rowNum).createCell(3).setCellValue("PENDING");
workbook.close();
}
你做的是对的,但是忘了写你的修改。 您需要打开一个输出流来写入这些更改。
FileOutputStream outputStream = new FileOutputStream("yourfile");
workbook.write(outputStream);
workbook.close();
outputStream.close();
希望这有效!!