将html表导出为已具有格式的excel文件 [英] exporting html table to excel file which already have a format

查看:88
本文介绍了将html表导出为已具有格式的excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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>





使用此代码exproting html table to excel。我的问题是我可以将html表导出到我已经制作的指定excel表模板。



using this code exproting html table to excel. My question is can i export html table to specified excel sheet template which i have already made.

推荐答案





如果您有浏览器IE8或更低版本,则无法通过javascript或jquery导出html表。



如果您使用的是其他浏览器并且代码不起作用然后检查安全问题。
Hi,

You can not export html table by javascript or jquery if you have browser IE8 or below version.

if you are using other browser and code not working then check then security issue.


这篇关于将html表导出为已具有格式的excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆