Export gridview to word and excel. ms word 2007 & excel 2007

Posted on 2009-12-17
Last Modified: 2013-11-25
Any one have the code for exporting a gridview to ms word 7.0 and excel 7.0
Question by:westdh
    LVL 11

    Accepted Solution

    protected void Button1_Click(object sender, EventArgs e)
            Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
            Response.Charset = String.Empty;
            Response.ContentType = "application/vnd.xls";
            System.IO.StringWriter sw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);
    LVL 11

    Expert Comment

    ive bounded the export with a button click event , you can relocate to any event you wish
    LVL 11

    Expert Comment

    fix the suitable MIME type for word export  n ths line Response.ContentType = "application/vnd.xls";

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now