Solved

GRIDVIEW EXPORT TO MS WORD

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

738 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