generating word document with header and footerwithout using word object.

S

srk

hi to all,
i need some help , my problem is that i have to generate a
word document withe the data from data base and it should be displayed
as tables in word and i have to insert some header and footer in word
along with the page number. i got the code for generating tables and
it is fine now i am trying for header and footer but i am failing
here. i am sending my code , just check it.


StringBuilder sbTop = new StringBuilder();

sbTop.Append(@"<html " +
"xmlns:eek:='urn:schemas-microsoft-
com:eek:ffice:eek:ffice' " +
"xmlns:w='urn:schemas-microsoft-
com:eek:ffice:word'" +
"xmlns='http://www.w3.org/TR/
REC-html40'>" +
"<head><title></title>");

sbTop.Append(@"<!--[if gte mso 9]>" +
"<xml>" +
//"<xmlns:w='urn:schemas-
microsoft-com:eek:ffice:word'>" +
"<w:WordDocument>" +
//"<w:sectPr><w:hdr><w:p><w:pPr><w:pStyle
w:val='Header'/></
w:pPr><w:r><w:t>My Header</w:t></w:r></w:p></w:hdr><w:sectPr>" +
"<w:View>Print</w:View>" +
"<w:Zoom>90</w:Zoom>" +
"</w:WordDocument>" +
"</xml>" +
"<![endif]-->");
sbTop.Append("<style>" +
"<!-- /* Style Definitions */" +
"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:12.0pt;}");

sbTop.Append("@page Section1" +
" {size:8.5in 11.0in; " +
" margin:1.0in 1.25in 1.0in
1.25in ; " +
" mso-header-margin:.5in; " +
" mso-footer: f1;" +
" mso-footer-margin:.5in; mso-
paper-source:0;}" +
" div.Section1" +
" {page:Section1;}" +
"-->" +
"</style></head>");

sbTop.Append(@"<body lang=EN-US
style='tab-interval:.5in'>");

sbTop.Append("<div style='mso-
element:footer' id=f1>" +
" <p class=MsoFooter>" +
" <span style='mso-tab-count:1'>my
footer</span>" +//<span style='mso-field-code:'PAGE''></span>" +
" </p></div>");



and here i am taking data from data base and and displaying through
html tables

and using the content-type for throwing the word file to save.

Response.AppendHeader("Content-Type", "application/msword");
Response.AppendHeader("Content-
disposition", "attachment;
filename=some1234.doc");
string strBody1=sbTop.ToString() +
strBody + bottom;
Response.Write(strBody1);







but it is not displaying footer but displaying the tables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top