Export datagrid to Excel
(Exportar un datagrid a Excel)
Usually I have to export reports to Excel. The most common way is make a web page which put the excel mime type and sends the report table
Response.ContentType = "application/vnd.ms-excel"
Response.Write(sReportTable)
If the reports are only queries to the database, is very simple, because you only have to pass the query to the page, but if you have to make some calculations you have to put the code in the page.
The solution is getting the outerHTML of the datagrid(DataGrid1 is the ID of the datagrid object in my .aspx page) and putting it in the clipboard. How?
<a href="#" onclick="var ret;ret = window.clipboardData.setData('Text',document.getElementById('DataGrid1').outerHTML);if(ret){alert('Copy OK');}else{alert('Copy failed');}">Copy</a>
Just open Excel an Edit-Paste
Permalink: Export datagrid to Excel
0 Comments:
Post a Comment
<< Home