?
Solved

GRIDVIEW EXPORT TO MS WORD

Posted on 2013-02-03
3
Medium Priority
?
802 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 2000 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
 

Author Closing Comment

by:BOEING39
ID: 38871428
Best answer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

765 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