Solved

GRIDVIEW EXPORT TO MS WORD

Posted on 2013-02-03
3
740 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now