私はジレンマに陥っています。Javaでhssf/xssfを介して既存のExcelファイルにデータを書き込もうとしています。エラーはありませんが、実行しても Excel シートに変更を加えることができません。誰でもこれで私を助けることができますか? 私のコードは次のとおりです。
try {
FileInputStream inp = new FileInputStream("C:/Users/Training/Desktop/saurav.xlsx");
Workbook wb = null;
try {
wb = WorkbookFactory.create(inp);
} catch (InvalidFormatException e) {
e.printStackTrace();
}
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(3);
Cell cell = row.getCell(4);
if (cell == null)
cell = row.createCell(4);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue("a test");
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("C:/Users/Training/Desktop/saurav.xlsx");
wb.write(fileOut);
fileOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
誰かがこれで私を助けてください.過去2日間からこれを試しています.