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
Nazeer AhamedNazeer Ahamed 

Generate MS Word doc from Visual force page

Hi.,

 

Have created MS word doc using Visual force (similar to standard Mail merge functionality).

 

Main Key is here,


<apex:page standardController="Order__c" recordSetVar="Order" showHeader="false" contentType="application/msword" extensions="Date_Update_ACL" action="{!update_date}">

 

The reason to move to custom functionality instead of using mail merge in Activity History, we need to generate mail merge doc for more than one record, upon generating the doc we need to update some fields in that record.

 

Here the problem is, our visual force page generate the MS Word doc in Fire Fox browser but not working in internet explorer.

 

I dont understand the reason, have you faced this kind of issue, any workaround for this? 

Any help appreciated.

 

Note: PDF can be generated easily but we need to generate in MS word

 

 

 

 

kirrankirran

hi..

i got it IE.

 

code for it is

<apex:page contentType="application/vnd.msword" cache="true">

 

 

please feel free to contact us for further info

 

from:

Dskvap Developer's Team,

email:kumar77@dskvap.com

ckumckum

Hi,

 

I am able to create Word Doc,but unable to get  Footer into it. Can you help me getting Footer for the Word Doc?

 

Regards,

ckum

jjainjjain

Hi,

Did you mean your custom VF page is supporting Mail Merge functionality ?

HsethHseth

Hi, I am trying to render a visualforce page as a word doc. The issue I am facing is that all the HTML code is being printed in the word doc. 

 

eg. 

 

<apex:outputLabel value="Test"></apex:outputLabel>

 

is being rendered as 

 

<label style="Font-weight:bold;">
Test</label> 

 

in the word doc. How can I handle this. need help

 

Regards

Himanshoo Seth

IsaygarciaIsaygarcia

Hi, I have a problem while generating a word document, I need the document to show on "Print Layout" view on MS Word, and also, I need to show the page number.

Is there a way to do this?

M.sfM.sf

By Default MS word will take the contents in Text/Html Format.

To open in print layout instead of web layout.

 

Include the following code in VF Page.

<apex:page controller="TestMSWord" contentType="application/msWord#msword.doc" >
<html xmlns:w="urn:schemas-microsoft-com:office:word">
<apex:outputText value="{!PrintView}" escape="false"/>
<body>
//All your code Goes Here
</body>
</html>
</apex:page>


In class Add the following

public class TestMSWord{
    public String getPrintView()
    {
        return
        '<!--[if gte mso 9]>' +
            '<xml>' +
            '<w:WordDocument>' +
            '<w:View>Print</w:View>' +
            '<w:Zoom>100</w:Zoom>' +
            '<w:DoNotOptimizeForBrowser/>' +
            '</w:WordDocument>' +
            '</xml>' +
            '<![endif]>';
        }
    }

 

Explanation:

Add <html> tag with attributes since it should understand the schema is of word
Add <body> tag so that it will allow html tags like <h1>, <ul>,<li> etc
Add <Outputext> from class since directly vf page will not allow to save the html content with <w:> tag.This will enable print view by default.

M.sfM.sf

Add <html><body> tags just after the <apex:page>.

Hope this resolve yur problem

ManojjenaManojjena
Hi I am facing problem to generate Doc file from Visual Force page .Image and the color of the div is not dispaying properly which is assigned from style class..
Below is the sample code 

<apex:page StandardController="Quote" extensions="Quote_Template_Cls" cache="true" contentType="application/msWord#msword.doc"a>
    <style>
       .header_holder{
            height:5.6em;
            border:1px solid #ccc;
            width:100%;
            background:#6d1f7e;
            color:#fff;
            font-size: 32px;
        }
    </style>
    <html xmlns:w="urn:schemas-microsoft-com:office:word">
        <body>
          <div class="logo"><apex:image url="{!$Resource.MILogo}" width="240" height="62"/></div>
          <div class="header_holder"> PROPOSAL FOR THE SUPPLY &amp;   INSTALLATION OF CODING &amp;  MARKING EQUIPMENT </div>
        </body>
    </html>
</apex:page>

Any help is highly appreciated .

 
M.sfM.sf
Hi Manoj,

Add the style after the body tag.
Can you please change your code like this.Hope it works for you.

<apex:page StandardController="Quote" extensions="Quote_Template_Cls" cache="true" contentType="application/msWord#msword.doc">
    <html xmlns:w="urn:schemas-microsoft-com:office:word">
        <body>
  <style>
       .header_holder{
            height:5.6em;
            border:1px solid #ccc;
            width:100%;
            background:#6d1f7e;
            color:#fff;
            font-size: 32px;
        }
    </style>
          <div class="logo"><apex:image url="{!$Resource.MILogo}" width="240" height="62"/></div>
          <div class="header_holder"> PROPOSAL FOR THE SUPPLY &amp;   INSTALLATION OF CODING &amp;  MARKING EQUIPMENT </div>
        </body>
    </html>
</apex:page>

 
Wagner Baldin 10Wagner Baldin 10
Hi!
I='ve got the problem with the Class, an error message :
"The property String PrintView is referenced by Visualforce Page (TestMSWord)  in salesforce.com. Remove the usage and try again."