问题
I want to create an excel sheet from click of button. These excel sheet will contain report which is generated on classic asp page. When user clicks on button then an excel sheet should be created which will have the same report as page have
回答1:
This header works fine:
<%
Response.AddHeader "Content-Disposition", "attachment;filename=NOMBRE_ARCHIVO.xls"
Response.ContentType = "application/vnd.ms-excel"
%>
For small tables, try this example in html/javascript:
<html>
<body>
<table id="tabla" border="1">
<tr><th>Uno</th><td>1</td></tr>
<tr><th>Dos</th><td>2</td></tr>
</table>
<p>
<input type="button" onclick="javascript:exportarExcel('tabla');" value="Vamos al excel!">
</p>
</body>
<script type="text/javascript">
function exportarExcel(tabla){
var t = document.getElementById(tabla);
t.border = 1;
var html = t.outerHTML;
html = encodeURIComponent(html);
// problemas con el encoding!
// se puede usar base64_encode() en lugar de encodeURIComponent(html))
// ojo con encodeURIComponet() que está deprecada. lo mejor sería usar base64
window.open('data:application/vnd.ms-excel,' + html);
}
</script>
</html>
来源:https://stackoverflow.com/questions/29791594/generate-excel-sheet-from-classic-asp-on-click-of-button