• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4733
  • Last Modified:

Hiding Header/Footer In ASP Generated Word Document

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

0
swinslow
Asked:
swinslow
1 Solution
 
brad2575Commented:
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
0
 
swinslowAuthor 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.
0
 
amb1313Commented:
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?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
swinslowAuthor 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

0
 
jhawarmayankCommented:
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?
0
 
jhawarmayankCommented:
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.
0
 
swinslowAuthor Commented:
You are right. My workaround is not a solution, but it appears that nobody else has any kind of answer at all.
0
 
jhawarmayankCommented:
So,if it is not a solution then I think the question should be kept open incase we do get an answer from somebody.
0
 
swinslowAuthor 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.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now