wef : write to xlsm (Excel 2007) using apache poi
When i write a simple string to the file, I am not able to open the file. Error - "Excel cannot open the file 'Test1.xlsm' because the file format or file extension is not valid"
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();
}