Export GridView Data to Word - ASP.NET

Some time we need to generate different kind of reports & need to save it in Excel or word Document for Local Reference, Or sending to other's. So here I create a code for achieve this task the first one is conversion data into Excel & second one is for Word Document.

// For pdf converstion we can use third party dll like ITextSharp

using System; 
public class Class1
    protected void btn_word_Click(object sender, EventArgs e)
        Response.ContentType = "application/vnd.word";
        System.IO.StringWriter swriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlwriter = new HtmlTextWriter(swriter);
        // Create a form to contain the gridview(MyGridView)
        HtmlForm mynewform = new HtmlForm();
        mynewform.Attributes["runat"] = "server";
Export GridView Data to Excel - ASP.NET 

Post a Comment