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.