Salesforce Visualforce pages can generate HTML and CSS content that is returned to the browser as a file with a .doc extension. Microsoft Word can then parse and open this file as a document, provided the markup meets Microsoft Word's requirements. This approach takes advantage of Microsoft Word's ability to interpret certain HTML-structured files as Office Open XML documents.
Note: Salesforce does not natively support generating true binary .doc files or standard .docx files (zipped Office Open XML documents). The approach described here generates an HTML-based file with a .doc extension that Microsoft Word can open. It is a workaround, not native document generation.
To generate a Word-compatible .doc file from a Visualforce page, configure the apex:page component with specific attributes that control the page output format.
Set the following three attributes on the apex:page component:
1. contentType="application/msword#filename.doc" This attribute instructs the browser to treat the Visualforce output as a Microsoft Word document download with the specified filename. Replace "filename.doc" with your desired file name.
2. applyHtmlTag="false" This attribute prevents Visualforce from auto-generating the outer <html> tag. Set this to false so you can provide your own <html> tag with the attributes Microsoft Word requires.
3. applyBodyTag="false" This attribute prevents Visualforce from auto-generating the <body> tag. Set this to false so you can fully control the body markup.
After setting these attributes, include complete <html> and <body> tags manually inside the apex:page component, with the HTML and CSS markup that Microsoft Word expects.
<apex:page controller="MyController" contentType="application/msword#filename.doc" sidebar="false" standardStylesheets="false" applyHtmlTag="false" applyBodyTag="false"> <html> <body> ... </body> </html>
Providing the specific HTML and CSS markup required by Microsoft Word to achieve particular document formatting is outside the scope of Salesforce Support. Salesforce Support can assist with the Visualforce configuration (the three attributes described above) but cannot assist with Microsoft Word-specific styling requirements.
000382324

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.