Write to XLSM (Excel) using Apache POI
Poi Download (remember to add all of the jar packages to the project OH) http://mirror.bit.edu.cn/apache/poi/
I have the written Java file for writing xlsm (Excel 2007).
Using the Apache POI Library, Writing xlsx file is success. and Writing xlsm file is success. But I can ' t open the xlsm file because in error when open xlsm file.
Would it feasible to write xlsm file using Apache POI Library?
If it is feasible to the write xlsm, please kindly provide the guide line how to write xlsm file using Apache Poi Library.
New= Workbook.createsheet ("related_src"= "test.xlsm"new File ("C:\\sdpapp ", realname); Try { new fileoutputstream (file); Workbook.write (fileOutput); Fileoutput.close (); Catch (Exception e) { // todo:handle Exception e.printstacktrace (); }
Thanks
According to the documentation of Apache POI It isn't possible to create Macros:http://poi.apache.org/spreadsheet/limitat Ions.html
However it ' s possible to read and re-write files containing macros and Apache POI would safely preserve the macros.
Here are an example:
String fileName = "C:\\new_file.xlsm";Try{Workbook Workbook; Workbook=NewXssfworkbook (Opcpackage.open ("Resources/template_with_macro.xlsm") ); //Do stuf with WORKBOOKFileOutputStream out=NewFileOutputStream (NewFile (fileName)); 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 ();}
The file is created won't give you an error
Java Operation Excel:poi cannot create a method for xlsm problems (from StackOverflow)