Export data to excel

Last post 11-06-2008 11:23 PM by duyhung2301. 4 replies.

Sort Posts:

  • Export data to excel

    10-13-2008, 4:42 PM
    • Member
      3 point Member
    • rajkm42
    • Member since 09-06-2007, 4:36 PM
    • Posts 71

     Hi friends,

        I want to read data from sql server db and export that data to excel sheet. I have a template excel file in which formulas are defined and a graph is placed.

    I want to use this template and create new excel file and the filename is specified on the fly.

    How can I do it in asp.net?

    Somewhere I found that to add reference for Microsoft.Excel 11.0 library

    and import the namespace, using System.Runtime.InteropServices.Marshal

    in the event procedures, Excel.Application exl = ...

    I am not getting the Excel. intellisence popup

    Any reply is highly appreciated.

  • Re: Export data to excel

    10-13-2008, 5:36 PM
    Answer
    • Member
      315 point Member
    • dec_obrien
    • Member since 09-22-2004, 4:54 PM
    • Dublin, Ireland
    • Posts 79

    This will get you started on Excel Object Model: http://msdn.microsoft.com/en-us/library/aa168292(office.11).aspx

  • Re: Export data to excel

    10-14-2008, 11:17 PM
    Answer

    Hi rajkm42,

    Export data to Excel is one of the most common functionality required in ASP.Net pages. Here are many references talking about this.

    And I found some of them quoted here. You may have a look at them

    http://www.codeproject.com/KB/custom-controls/Excel_CSV_export_button.aspx

    http://www.c-sharpcorner.com/uploadfile/dipalchoksi/exportaspnetdatagridtoexcel11222005041447am/exportaspnetdatagridtoexcel.aspx

    http://www.developer.com/net/asp/article.php/3633891

    Best Regards,
    Shengqing Yang

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )
  • Re: Export data to excel

    10-14-2008, 11:58 PM
    Answer
    • Member
      314 point Member
    • inbaa
    • Member since 08-19-2006, 5:08 AM
    • Posts 237

    string strFileName;

    DataGrid dg
            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
            Response.ContentType = "application/excel";
            System.IO.StringWriter sw = new System.IO.StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            dg.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();

    Filed under:
  • Re: Export data to excel

    11-06-2008, 11:23 PM
    • Member
      2 point Member
    • duyhung2301
    • Member since 05-08-2008, 5:21 AM
    • Posts 11

    I export data  from gridview to file excel to appear error font.It only true when run at localhost and error font when run in server

    please ,help me.

Page 1 of 1 (5 items)