Friday, April 18, 2014

How to Generate MS-Word document using VF pages?

How to Generate MS-Word document using VF pages?



I have a VF which renders as MS-Word. for this you need to mention content type in <apex:page> tag. 

EX:-

<apex:page standardController="Account"  contentType="application/msword#sfdcsrini.doc" cache="true">

<html xmlns:w="urn:schemas-microsoft-com:office:word">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<body>
<apex:outputText title="Welcome to word" value="{!$User.FirstName}"/>
<br/>
<br/>
<apex:pageBlock >
<div style="text-align:left" >
<b>Account Name :</b><apex:outputText value="{!account.name}"/><br/>
<b>Account Number: </b><apex:outputText value="{!account.AccountNumber}"/><br/>
</div>            
</apex:pageBlock>
</body>
</html>


</apex:page>


once you save this code in to your vf page you need to pass the account id in to url like

https://c.ap1.visual.force.com/apex/worddocvf?id=0019000000RMAaF


 here contentType="application/msword#sfdcsrini.doc" tells that page should render as ms-word document.(sfdcsrini) is the name of the document in content type, you can give your own name. 




5 comments:

Unknown said...

Hi Srini,
Any apporach for "docx" documents.
Thanks
Arshad

Unknown said...

There is more information for us.I really impress to visit your website.It is so good.Thanks for sharing with us.
Run 4 Cat Ninja Ludo Star

Yakin said...

https://sourcecalendar.com/april-2018-calendar


https://sourcecalendar.com/july-2018-calendar


https://sourcecalendar.com/june-2018-calendar


https://sourcecalendar.com/may-2018-calendar

nick jones said...


thanks for sharing..
Server and Storage

kalyan said...

how to generate vfpage in format of (.docx)?
can u tell me.

Thanks

Post a Comment

 
| ,