Data in Grid or DataTable is exported to Excel so simple _ practical tips

Source: Internet
Author: User
It has always been thought that exporting data from a grid or DataTable to Excel can be very complicated, and you might want to use a library or something or it's too hard to use CSV.

Looking at the implementation of the Fineui in the grid as Excel, it can actually be very simple. It seems difficult to change a way of thinking can be very simple.
1. aspx background code output content type information
Copy Code code as follows:

Response.clearcontent ();
Response.AddHeader ("Content-disposition", "attachment; Filename=myexcelfile.xls ");
Response.ContentType = "Application/excel";
Response.Write (getgridtablehtml (GRID1));
Response.End (); 2. Direct output HTML code
Response.Write (@ "
<table border= "1" >
<tr>
<td>Excel</td>
<td>by html</td>
</tr>
</table> ")

Such implementations are sufficient for simple export of data to Excel.
Test method: Directly save the HTML code as an Excel file, you can see the effect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.