Live Chat Icon For mobile
Live Chat Icon

How to export data in Datagrid on a webform to Microsoft Excel

Platform: ASP.NET| Category: DataGrid

Two techniques for exporting the data in the DataGrid:

  • Using the Excel MIME Type (or Content Type)

    With server-side code, you can bind the DataGrid to your data and have the data open in Excel on a client computer. To do this, set the ContentType to application/vnd.ms-excel. After the client receives the new stream, the data appears in Excel as if the content was opened as a new page in the Web browser.

  • Using Excel Automation
    With client-side code, you can extract the HTML from the DataGrid and then Automate Excel to display the HTML in a new workbook. With Excel Automation, the data always appears outside the browser in an Excel application window. One advantage to Automation is that you can programmatically control Excel if you want to modify the workbook after the data is exported. However, because Excel is not marked as safe for scripting, your clients must apply security settings in the Web browser that allow Automation.

For more details refer How To Export Data in a DataGrid on an ASP . NET WebForm to Microsoft Excel

Share with

Share on twitter
Share on facebook
Share on linkedin