Generate excel sheet from classic asp on click of button

青春壹個敷衍的年華 提交于 2020-02-07 10:52:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!