• JS导出gridview到excel


    <html>
    <head>
        <script type="text/javascript">
            var tableToExcel = (function () {
                var uri = 'data:application/vnd.ms-excel;base64,'
        , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
        , base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
        , format = function (s, c) { return s.replace(/{(w+)}/g, function (m, p) { return c[p]; }) }
                return function (table, name) {
                    if (!table.nodeType) table = document.getElementById(table)
                    var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
                    window.location.href = uri + base64(format(template, ctx))
                }
            })()
        </script>
    </head>
    <body>
        <h1>
            tableToExcel Demo</h1>
        <p>
            Exporting the W3C Example Table</p>
        <input type="button" onclick="tableToExcel('GridViewBoiler', 'W3C Example Table')"
            value="Export to Excel">
        <table cellspacing="0" cellpadding="4" rules="all" border="1" id="Table1" style="color: #333333;
             100%; border-collapse: collapse;">
            <tbody>
                <tr style="color: White; background-color: #507CD1; font-weight: bold;">
                    <th scope="col">
                        序号
                    </th>
                    <th scope="col">
                        参数描述
                    </th>
                    <th scope="col">
                        --望亭发电有限公司--#11机组--锅炉本体试验--2015-02-09 14:40:53--
                    </th>
                </tr>
                <tr style="background-color: #EFF3FB;">
                    <td align="center">
                        1
                    </td>
                    <td align="left">
                        入炉煤收到基低位发热量(KJ/Kg)
                    </td>
                    <td>
                        19600.0000
                    </td>
                </tr>
                <tr style="background-color: White;">
                    <td align="center">
                        2
                    </td>
                    <td align="left">
                        入炉煤收到基灰分(%)
                    </td>
                    <td>
                        23.6000
                    </td>
                </tr>
                <tr style="background-color: #EFF3FB;">
                    <td align="center">
                        3
                    </td>
                    <td align="left">
                        入炉煤收到基水分(%)
                    </td>
                    <td>
                        4.1800
                    </td>
                </tr>
                <tr style="background-color: White;">
                    <td align="center">
                        4
                    </td>
                    <td align="left">
                        入炉煤收到基碳含量(%)
                    </td>
                    <td>
                        57.4900
                    </td>
                </tr>
                <tr style="background-color: #EFF3FB;">
                    <td align="center">
                        5
                    </td>
                    <td align="left">
                        入炉煤收到基氢含量(%)
                    </td>
                    <td>
                        3.6500
                    </td>
                </tr>
                <tr style="background-color: White;">
                    <td align="center">
                        6
                    </td>
                    <td align="left">
                        入炉煤收到基氧含量(%)
                    </td>
                    <td>
                        9.9500
                    </td>
                </tr>
                <tr style="background-color: White;">
                    <td align="center">
                        20
                    </td>
                    <td align="left">
                        换算至设计送风温度时的排烟温度(%)
                    </td>
                    <td>
                        122.0239
                    </td>
                </tr>
                <tr style="background-color: #EFF3FB;">
                    <td align="center">
                        21
                    </td>
                    <td align="left">
                        修正后锅炉热效率(%)
                    </td>
                    <td>
                        91.2669
                    </td>
                </tr>
            </tbody>
        </table>
    </body>
    </html>
  • 相关阅读:
    微信 播放视频
    json与页面动态绑定
    layer mobile开发layer.full
    Layer 使用
    分享一段,图片加水印的代码。本人修改过多次
    jenkins .net linux
    Jenkins .net windows
    《微服务-架构与实践》
    分布式网站架构
    Go 并发随机打印1-n
  • 原文地址:https://www.cnblogs.com/ilookbo/p/5057245.html
Copyright © 2020-2023  润新知