Skip to main content
Inspiring
July 25, 2016
Answered

Dynamically generated Word doc has double headers and footers

  • July 25, 2016
  • 1 reply
  • 2935 views

Hi,

I'm able to use CFcontent and CFheader tags etc. to generate a Word doc with dynamic data on the fly and such Word doc has several pages.  An issue is the last page has double headers and footers.  The following is the process:

1) <cfsavecontent 
    variable = "WDcontent">

2) Use Microsoft XML and Word style guide

<html xmlns:o="urn:schemas-microsoft-com:office:office"
      xmlns:w="urn:schemas-microsoft-com:office:word"
      xmlns="http://www.w3.org/TR/REC-html40">

<head>

<style>

  1. p.MsoHeader, li.MsoHeader, div.MsoHeader
        {margin:0in;
        margin-bottom:.0001pt;
        mso-pagination:widow-orphan;
        tab-stops:center 3.0in right 6.0in;}

    p.MsoFooter, li.MsoFooter, div.MsoFooter
        {margin:0in;
         margin-bottom:.0001pt;
         mso-pagination:widow-orphan;
         tab-stops:center 3.0in right 6.0in;
         font-size:10.0pt;}
                                   
    @4025150 Section1
        {size:8.5in 11.0in;
         margin:1.0in 1.25in 1.0in 1.25in ;
         mso-header: h1;
         mso-footer: f1;
         mso-header-margin:.5in;
         mso-footer-margin:.5in; mso-paper-source:0;}
    div.Section1 
        {page:Section1;}

    // header & footer area
    table#hrdftrtbl
    {
        margin:0in 0in 0in 9in;
    }    

</style>

3) continue with HTML body output

toward the end and before the top level DIV ends,

add the header and footer reference,

    <table id='hrdftrtbl' border='0' cellspacing='0' cellpadding='0'>
        <tr>
            <td>
                <div style='mso-element: header' id="h1">
                    <p style='text-align: center'>
                    <img src="#baseURL#/header2.png" width="90%" height="75">
                    </p>
                </div>
            </td>
   
            <td>   
                <div style='mso-element: footer' id="f1">
                    <p align="right">
                        <span style=mso-tab-count:2'>
                        <img src="#baseURL#/footer2.png" width="90%" height="15">
                        </span>
                        </p>
                </div>
            </td>
        </tr>       
    </table>

Then, after HTML closing


</cfsavecontent>

4) direct output to Word

<!--- WORD version --->
<cfheader name="content-disposition" value="filename=myNew.doc">
<cfcontent type="application/msword">

<cfprocessingdirective suppressWhiteSpace = "true">
<cfoutput>#WDcontent#</cfoutput>
</cfprocessingdirective>

Thoughts?

tia.

This topic has been closed for replies.
Correct answer ghfftttyyudsderycv76

Solved.

1 reply

ghfftttyyudsderycv76AuthorCorrect answer
Inspiring
July 26, 2016

Solved.

WolfShade
Braniac
July 26, 2016

Please share.  I'm curious, myself.  And maybe someone else runs across the same issue, and could use your wisdom on this.

V/r,

^_^

Carl Von Stetten
Braniac
August 1, 2016

pm me.


Unless your code is proprietary, it would be better to post your solution here (as WolfShade​ suggested) for the future benefit of anyone who encounters the same issue.  If you aren't willing to do that, then maybe you can delete the question entirely so it doesn't become a "dead end" of frustration for those who come along later.


Thank you,

-Carl V. - Moderator