Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Convert .xltm to .xlsm using apache poi

981207Nov 25 2016 — edited Nov 25 2016

Dear All,

i am using jdeveloper version of 12.1.3.0 and poi version of 3.9.

I have a template named Test.xltm in my database.On click of download button i want to convert the Test.xltm to Test.xlsm.

Default extension given is Test .xls and it is downloading without any issues.

But when i change the filename (Test.xlsm) in business logic, i am getting invalid file format or file corrupted while opening the file .

Below is my code :

String filename=Test.xls;

ExternalContext econtext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) econtext.getResponse();

Sheet sheet;

response.setContentType("application/force-download");

response.setHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");

BlobDomain template = (BlobDomain) ExcelRowvo.getAttribute("Template");  ----> getting .xltm template

InputStream is = template.getInputStream();

Workbook workbook = new XSSFWorkbook(OPCPackage.create(filename));  ----->creating .xlsm file

sheet = workbook.getSheetAt(0);

is.read();

please tell me how to write .xltm to .xlsm for downloading the file as Test.xlsm

Thanks

Comments

Timo Hahn

I guess the content type you are using is confusing the browser. Here are the correct content type for Office

Extension MIME Type
.doc application/msword
.dot application/msword

.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx application/vnd.openxmlformats-officedocument.wordprocessingml.template
.docm application/vnd.ms-word.document.macroEnabled.12
.dotm application/vnd.ms-word.template.macroEnabled.12

.xls application/vnd.ms-excel
.xlt application/vnd.ms-excel
.xla application/vnd.ms-excel

.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx application/vnd.openxmlformats-officedocument.spreadsheetml.template
.xlsm application/vnd.ms-excel.sheet.macroEnabled.12
.xltm application/vnd.ms-excel.template.macroEnabled.12
.xlam application/vnd.ms-excel.addin.macroEnabled.12
.xlsb application/vnd.ms-excel.sheet.binary.macroEnabled.12

.ppt application/vnd.ms-powerpoint
.pot application/vnd.ms-powerpoint
.pps application/vnd.ms-powerpoint
.ppa application/vnd.ms-powerpoint

.pptx application/vnd.openxmlformats-officedocument.presentationml.presentation
.potx application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx application/vnd.openxmlformats-officedocument.presentationml.slideshow
.ppam application/vnd.ms-powerpoint.addin.macroEnabled.12
.pptm application/vnd.ms-powerpoint.presentation.macroEnabled.12
.potm application/vnd.ms-powerpoint.template.macroEnabled.12
.ppsm application/vnd.ms-powerpoint.slideshow.macroEnabled.12

So I would try to use 'application/vnd.ms-excel.sheet.macroEnabled.12'.

Timo

1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 23 2016
Added on Nov 25 2016
1 comment
819 views