BOEING39
asked on
GRIDVIEW EXPORT TO MS WORD
Please find the code below which exports gridview to MS word. I need for this to export to Leagal paper. Can anyone assist with this? Right now it is export to 8.5 to 11" landscape.
Response.Clear();
Response.Buffer = true;
Response.AddHeader("conten t-disposit ion", "attachment;filename=GridV iewExport. doc");
Response.Charset = ""; Response.ContentType = "application/vnd.ms-word ";
Response.Write("<html>");
Response.Write("<head>");
Response.Write("<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=UTF-8'>");
Response.Write("<meta name=ProgId content=Word.Document>");
Response.Write("<meta name=Generator content='Microsoft Word 9'>");
Response.Write("<meta name=Originator content='Microsoft Word 9'>");
Response.Write("<style>");
Response.Write("@page Section1 {size:595.45pt 841.7pt; margin:1.0in 1.25in 1.0in 1.25in;mso-header-margin:. 5in;mso-fo oter-margi n:.5in;mso -paper-sou rce:0;}");
Response.Write("div.Sectio n1 {page:Section1;}");
Response.Write("@page Section2 {size:841.7pt 595.45pt;mso-page-orientat ion:landsc ape;margin :1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5 in;mso-foo ter-margin :.5in;mso- paper-sour ce:0;}");
Response.Write("div.Sectio n2 {page:Section2;}");
Response.Write("</style>") ;
Response.Write("</head>");
Response.Write("<body>");
Response.Write("<div class=Section2>");
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GridView1.DataBind();
GridView1.RenderControl(hw );
Response.Write(sw.ToString ());
Response.Write("</div>");
Response.Write("</body>");
Response.Write("</html>");
Response.Flush();
Response.End();
}
public override void VerifyRenderingInServerFor m(Control control)
{
}
}
Response.Clear();
Response.Buffer = true;
Response.AddHeader("conten
Response.Charset = ""; Response.ContentType = "application/vnd.ms-word ";
Response.Write("<html>");
Response.Write("<head>");
Response.Write("<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=UTF-8'>");
Response.Write("<meta name=ProgId content=Word.Document>");
Response.Write("<meta name=Generator content='Microsoft Word 9'>");
Response.Write("<meta name=Originator content='Microsoft Word 9'>");
Response.Write("<style>");
Response.Write("@page Section1 {size:595.45pt 841.7pt; margin:1.0in 1.25in 1.0in 1.25in;mso-header-margin:.
Response.Write("div.Sectio
Response.Write("@page Section2 {size:841.7pt 595.45pt;mso-page-orientat
Response.Write("div.Sectio
Response.Write("</style>")
Response.Write("</head>");
Response.Write("<body>");
Response.Write("<div class=Section2>");
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GridView1.DataBind();
GridView1.RenderControl(hw
Response.Write(sw.ToString
Response.Write("</div>");
Response.Write("</body>");
Response.Write("</html>");
Response.Flush();
Response.End();
}
public override void VerifyRenderingInServerFor
{
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Best answer
http://www.aspdotnet-suresh.com/2011/04/how-to-export-gridview-data-to-excel-or.html
http://csharp-guide.blogspot.in/2012/06/aspnet-export-gridview-to-word-document.html