我想在Java中读取和修改.xlsm文件,并且我正在使用Apache POI。在写入.xlsm文件时,我的代码正在创建0 kb文件。相同的代码在xls格式下也可以正常工作,但在.xlsm格式的情况下,它将创建0 kb文件。谁能帮助我。
try {
FileInputStream inputStream = new FileInputStream(new File("Scoring_03101995.xlsm"));
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheet = workbook.getSheetAt(1);
Cell celltUpdate = sheet.getRow(5).getCell(2); //Scoring_03101995 file contains 5 sheets and each sheet has more than 20 rows and 100 cells
celltUpdate.setCellValue(123);
inputStream.close();
FileOutputStream outputStream = new FileOutputStream("Scoring_03101995.xlsm");
workbook.write(outputStream);
//((FileInputStream) workbook).close();
outputStream.close();
} catch (IOException | EncryptedDocumentException ex) {
ex.printStackTrace();
}