function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhi1704Abhi1704 

Issues to generate docx or xlsx file from Visualforce Page

We are using visualforce page to generate .docx file in salesforce. Everything works fine if we try with .doc and .xls files but we are facing some issues while generating only on docx and xlsx files, for doc and xl files its works fine. While opening downloaded it some error messages are throwing and only after clicking on those popup boxes we are unable to view the files.

We have tried mime-type "application/vnd.openxmlformats-officedocument.wordprocessingml.document" with no luck. You can find mime-type reference from below link:

https://www.sitepoint.com/web-foundations/mime-types-summary-list

If visualforce doesn't support to generate .docx or .xlsx file please help me to find any doc which stated that?
Best Answer chosen by Abhi1704
Abhi1704Abhi1704
Based on my R&D we can create only blank .docx file. But whenever I was trying to write anything between page attribute it produces error.
So we can say salesforce doen't support to create .docx file.

For example:
Code:
<apex:page contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document#filename.docx;" cache="true"> </apex:page> 
Result: .docx gets open without error

One Major point while generating the .doc file which I have realized, after downloading when we will try to open the generated .doc file and save this file it generates one folder for html stuffs. If you are facing this issue please refer the below code to resolve:

Code:
<apex:page controller="MyController" contentType="application/msword#filename.doc" sidebar="false" standardStylesheets="false"
applyHtmlTag="false" applyBodyTag="false">
</apex:page>

Please let me know if it help you.

All Answers

Arshadulla ShariffArshadulla Shariff
Hello Abhinav
Any work around for the above problem.I am also experiencing a similar problem .
Let me know any solution if you found .arshadulla88@gmail.com
Thanks
Abhi1704Abhi1704
Based on my R&D we can create only blank .docx file. But whenever I was trying to write anything between page attribute it produces error.
So we can say salesforce doen't support to create .docx file.

For example:
Code:
<apex:page contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document#filename.docx;" cache="true"> </apex:page> 
Result: .docx gets open without error

One Major point while generating the .doc file which I have realized, after downloading when we will try to open the generated .doc file and save this file it generates one folder for html stuffs. If you are facing this issue please refer the below code to resolve:

Code:
<apex:page controller="MyController" contentType="application/msword#filename.doc" sidebar="false" standardStylesheets="false"
applyHtmlTag="false" applyBodyTag="false">
</apex:page>

Please let me know if it help you.
This was selected as the best answer