We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Hiding Header/Footer In ASP Generated Word Document

swinslow
swinslow asked
on
Medium Priority
5,118 Views
Last Modified: 2012-05-06
I am generating a word document from a form. The word document contains a header and footer. The header and footer work well. However what happens is that I end up with is the header and footer content as part of the main content at the end of the document as well as where they are suppose to go. How do I hide them (without creating a separate header file).
<%
 
Response.ContentType = "application/vnd.ms-word"
Response.AddHeader "content-disposition", "attachment; filename=TestWordDoc.doc"
 
%>
 
<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>
 
<xml>
<w:WordDocument>
<w:View>Print</w:View>
<w:Zoom>100</w:Zoom>
<w:DoNotOptimizeForBrowser/>
</w:WordDocument>
</xml>
 
<style>
 
@page Section1
{
size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:35.4pt;
mso-footer-margin:35.4pt;
mso-header:h1;
mso-footer:f1;
mso-paper-source:0;
mso-gutter-direction:rtl;
}
div.Section1
{page:Section1;}
</style>
 
<title>Test Word Document</title>
 
</head>
 
<body lang=EN-US style='tab-interval:.5in'>
 
<div class=Section1>
 
<%
  Response.Write "<p>A bunch of stuff will go here that is dynamicly generated<p>"
%>
 
</div>
 
   <div style='mso-element:header'  id=h1>
        <p class=MsoHeader style='text-align:center'>
           Test Word Document Header
        </p>
    </div>
 
   <div style='mso-element:footer' id=f1>
       Test Word Document Footer <span style='mso-field-code:" PAGE "'></span>
   </div>
 
</body>
 
</html>

Open in new window

Comment
Watch Question

Commented:
are you passing some variable to the page so you know when someone requests it to be a word.doc?

If so you can just do an if check at the top of the page:

If wordcheckvaraiable = "" Then
' display header here
else
' dont display header
' and do put this:
Response.ContentType = "application/vnd.ms-word"
Response.AddHeader "content-disposition", "attachment; filename=TestWordDoc.doc"
 
end if

I do something exactly like this with Excel all the time, that way I dont have to build a separate page for the file download and one for the display

Author

Commented:
Brad, I think you have missed my point. Even if I was not passing any data, my form would be generating a word document. The passing of data  or creating a word document is not the question here.

Commented:
I'm having this same problem as well.    When I include a footer it also includes it on the last page twice.   Once in the actual footer and again at the very end of the actual word document at the end of the content.   Any idea on how I can hide the duplicate that shows up in the actual document?
Commented:
What I have done as a temporary work-around is put <br clear="all" style="page-break-before:always"> before the last div of the main content. What it does is creates an extra page. The extra page will still have duplicate header and footer, but at least it does not put a dupilcate header and footer on the last page of actual content.


<%
 
Response.ContentType = "application/vnd.ms-word"
Response.AddHeader "content-disposition", "attachment; filename=TestWordDoc.doc"
 
%>
 
<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>
 
<xml>
<w:WordDocument>
<w:View>Print</w:View>
<w:Zoom>100</w:Zoom>
<w:DoNotOptimizeForBrowser/>
</w:WordDocument>
</xml>
 
<style>
 
@page Section1
{
size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:35.4pt;
mso-footer-margin:35.4pt;
mso-header:h1;
mso-footer:f1;
mso-paper-source:0;
mso-gutter-direction:rtl;
}
div.Section1
{page:Section1;}
</style>
 
<title>Test Word Document</title>
 
</head>
 
<body lang=EN-US style='tab-interval:.5in'>
 
<div class=Section1>
 
<%
  Response.Write "<p>A bunch of stuff will go here that is dynamicly generated<p>"
%>
 
<br clear="all" style="page-break-before:always">
</div>
 
   <div style='mso-element:header'  id=h1>
        <p class=MsoHeader style='text-align:center'>
           Test Word Document Header
        </p>
    </div>
 
   <div style='mso-element:footer' id=f1>
       Test Word Document Footer <span style='mso-field-code:" PAGE "'></span>
   </div>
 
</body>
 
</html>

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
I am facing the same problem, that while generating the word doc, the header is being repeated twice on the first page.Once in the header itself and once more in the content part of the page? Is there any way to get rid of this extra header in the content part of the page?
This question has not yet been answered.The work around provided by swinslow is not a solution.And,the problem is with the header and footer being repeated on the first page and not the last page.
I request the community to keep the question opened for solutions from the experts community.

Author

Commented:
You are right. My workaround is not a solution, but it appears that nobody else has any kind of answer at all.
So,if it is not a solution then I think the question should be kept open incase we do get an answer from somebody.

Author

Commented:
However, since nobody has a solution other than my workaround, I would like to get a refund on my points. If you want tie up your points in a question where nobody has a solution, then go for it.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.