[SalesForce] How to add header & footer in VF page whose content type is word

I have a Vf page which renders as a word document. This word document needs to have a header & a footer with page counter & image (logo). The same code for rendering page as PDF doesnt work in style class.

Best Answer

You will need the mso-header, mso-footer and mso-pagination style attributes. For more info you can download official misrosoft lib: Microsoft Office HTML and XML Reference

Something like this:

<apex:page sidebar="false"
           showChat="false"
           showHeader="false"
           contentType="application/msword#Test.doc" 
           cache="true">

<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style>
    @page Main {
        mso-header:h1;
        mso-footer:f1;
    }
    div.Main{
        page:Main;
    }
    p.MyFoot, li.MyFoot, div.MyFoot{
        mso-pagination:widow-orphan;
        tab-stops:center 216.0pt right 432.0pt;
    }
    p.MyHead {

    }
</style>
</head> 

<div class="Main">
    <div style="mso-element:header" id="h1">
        <p class="MyHead">Header Text</p>
    </div>
    <div style="mso-element:footer" id="f1">
        <p class="MyFoot">
            <span style='mso-field-code:" FILENAME "'> </span>
            <span style='mso-tab-count:2'></span>
            Page <span style='mso-field-code:" PAGE "'></span> of <span style='mso-field-code:" NUMPAGES "'></span>
        </p>
    </div>
</div>

</apex:page>
Related Topic