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
neophyteneophyte 

Word attachments in visualforce email templates

Hi,

 

I am trying to create a word file attachment in the visualforce email template. The code I use inside the template is as follows:

 

<messaging:attachment filename="{!relatedTo.name}.doc" > 
    <html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word">
    <head>
    <meta name="contentType"
    <meta name="ProgId" content="Word.Document" />
    <meta name="Generator" content="Microsoft Word 12" />
    <meta name="Originator" content="Microsoft Word 12" />
    
    </head>
    
    <body>
<div>
<table>       
<apex:repeat var="cx" value="{!relatedTo.ChildRelationName__r}">
<tr>
<td> <apex:outputField value="{!cx.field1__c}"/> </td>
<td> <apex:outputField value="{!cx.field2__c}"/> </td>
<td> <apex:outputField value="{!cx.field3__c}"/> </td>
</tr>
</apex:repeat>
</table>
</div>
</body>
</html>

</messaging:attachment>

 

 

But the attached word file always shows error when I try to open it.

 

We could set the attribute contentType="application/msword" for apex:page, but I don't seem to find any such attribute for messagin:attachment.

 

I just wanted to know if anyone has done this? Any help is appreciated!!

 

Thanks!!