Exporting data to Excel in Grid or DataTable is as simple as that

  • 2020-05-19 04:33:57
  • OfStack

Previously 1 had assumed that exporting data from Grid or DataTable to the Excel implementation would be very complex, that you might want to use a library or something, or that it would be too difficult to just use csv.

Looking at the implementation of exporting Grid to Excel in FineUI, it can actually be very simple. For seemingly difficult problems, it is very easy to change one way of thinking.
1. Aspx background code outputs Content Type information
 
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>") 

This implementation is sufficient for the simple export of data to Excel.
Check: save the html code as Excel to see the effect.

Related articles: