wef :使用 apache poi 写入 xlsm (Excel 2007)
当我将一个简单的字符串写入文件时,我无法打开文件。错误 - “Excel 无法打开文件 'Test1.xlsm',因为文件格式或文件扩展名无效”
try {
Workbook workbook;
workbook = new XSSFWorkbook(OPCPackage.open("C:\\temp\\Test.xlsm"));
String content = "This is the text content";
byte[] contentInBytes = content.getBytes();
FileOutputStream out = new FileOutputStream("C:\\temp\\Test1.xlsm");
out.write(contentInBytes);
workbook.write(out);
out.close();
System.out.println("xlsm created successfully..");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}