Solved

GRIDVIEW EXPORT TO MS WORD

Posted on 2013-02-03
3
762 Views
Last Modified: 2013-02-09
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)
    {

    }


}
0
Comment
Question by:BOEING39
3 Comments
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 500 total points
ID: 38850182
Please do refer http://forums.asp.net/t/1695126.aspx/1

Response.Write("@page Section1 ......
Response.Write("@page Section2 ......

Apply your changes in above 2 lines of code. There it is set as Landscape. If you want portrait please do change accordingly.
0
 
LVL 19

Expert Comment

by:Manoj Patil
ID: 38850292
0
 

Author Closing Comment

by:BOEING39
ID: 38871428
Best answer
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question