Java Operation Excel:poi cannot create a method for xlsm problems (from StackOverflow)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.