Loading

Convert a Salesforce Visualforce Page to a Word (.doc) Document Using the contentType Attribute

게시 일자: Jun 8, 2026
상세 설명

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.

How to Configure the Visualforce Page

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>

Scope and Support Limitations

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.

Knowledge 기사 번호

000382324

 
로드 중
Salesforce Help | Article