Link to home
Start Free TrialLog in
Avatar of BOEING39
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("content-disposition", "attachment;filename=GridViewExport.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-footer-margin:.5in;mso-paper-source:0;}");      
    Response.Write("div.Section1 {page:Section1;}");      
    Response.Write("@page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}");      
    Response.Write("div.Section2 {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 VerifyRenderingInServerForm(Control control)
    {

    }


}
ASKER CERTIFIED SOLUTION
Avatar of Easwaran Paramasivam
Easwaran Paramasivam
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BOEING39
BOEING39

ASKER

Best answer