{"id":3256,"date":"2024-11-10T14:28:35","date_gmt":"2024-11-10T06:28:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3256\/"},"modified":"2024-11-10T14:28:35","modified_gmt":"2024-11-10T06:28:35","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-javascript-%e5%af%bc%e5%87%ba%e5%a4%9a%e4%b8%aa-html-%e8%a1%a8%e6%a0%bc%e5%88%b0%e5%8d%95%e4%b8%aa-excel-%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3256\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 JavaScript \u5bfc\u51fa\u591a\u4e2a HTML \u8868\u683c\u5230\u5355\u4e2a Excel \u6587\u4ef6?"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173102564995855.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u5bfc\u51fa\u591a\u4e2a HTML \u8868\u683c\u5230\u5355\u4e2a Excel \u6587\u4ef6?\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u5bfc\u51fa\u591a\u4e2a HTML \u8868\u683c\u5230\u5355\u4e2a Excel \u6587\u4ef6?\u63d2\u56fe\" \/><\/p>\n<p><strong>js \u5bfc\u51fa excel \u95ee\u9898\u89e3\u51b3<\/strong><\/p>\n<p>\u5f53\u4f7f\u7528 javascript \u5bfc\u51fa excel \u65f6\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u4e00\u6b21\u5bfc\u51fa\u591a\u4e2a\u8868\u3002\u672c\u6587\u5c06\u63a2\u8ba8\u5982\u4f55\u901a\u8fc7\u83b7\u53d6 html \u9875\u9762\u4e2d\u7684\u6570\u636e\u6765\u5b9e\u73b0\u6b64\u529f\u80fd\u3002<\/p>\n<p>\u6211\u4eec\u4f7f\u7528\u7684\u662f\u57fa\u672c\u7684\u65b9\u6cd5\uff0c\u5373\u63d0\u53d6 html \u8868\u683c\u7684\u5185\u5bb9\u5e76\u5c06\u5176\u653e\u5165 excel \u4e2d\u3002\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>var tabletoexcel = (function () {\n    var uri = 'data:application\/vnd.ms-excel;base64,';\n    var template = '&lt;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\"&gt;&lt;head&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;&lt;x:excelworkbook&gt;&lt;x:excelworksheets&gt;&lt;x:excelworksheet&gt;&lt;x:name&gt;{worksheet}&lt;\/x:name&gt;&lt;x:worksheetoptions&gt;&lt;x:displaygridlines&gt;&lt;\/x:displaygridlines&gt;&lt;\/x:worksheetoptions&gt;&lt;\/x:excelworksheet&gt;&lt;\/x:excelworksheets&gt;&lt;\/x:excelworkbook&gt;&lt;\/xml&gt;&lt;![endif]--&gt;&lt;\/head&gt;&lt;body&gt;&lt;table&gt;{table}&lt;\/table&gt;&lt;\/body&gt;&lt;\/html&gt;';\n    var base64 = function (s) {\n        return window.btoa(unescape(encodeuricomponent(s)))\n    }\n    var format = function (s, c) {\n        return s.replace(\/{(w+)}\/g, function (m, p) {\n            return c[p];\n        })\n    }\n    return function (table, name, filename) {\n        if (!table.nodetype) table = document.getelementbyid(table)\n        var ctx = { worksheet: name || 'worksheet', table: table.innerhtml }\n\n        window.location.href = uri + base64(format(template, ctx));\n    }\n})();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7528\u6cd5<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u8981\u5bfc\u51fa\u4e00\u4e2a\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>tabletoexcel('table1', 'table1', 'table1.xls');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8981\u5bfc\u51fa\u591a\u4e2a\u8868\uff0c\u53ef\u4ee5\u5c06\u5b83\u4eec\u653e\u5165\u4e00\u4e2a\u5305\u542b\u7684 div \u4e2d\uff0c\u5e76\u4f20\u9012\u8be5 div \u7684 id\uff1a<\/p>\n<pre>tableToExcel('container-div', 'CombinedTables', 'combined.xls');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\uff1a<\/strong>\u6b64\u65b9\u6cd5\u4ec5\u9002\u7528\u4e8e\u5c11\u91cf\u8868\uff0c\u56e0\u4e3a html \u5185\u5bb9\u4f1a\u53d8\u5927\uff0c\u5e76\u4e14\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u95ee\u9898\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 JavaScript \u5bfc\u51fa\u591a\u4e2a HTML \u8868\u683c\u5230\u5355\u4e2a Excel \u6587\u4ef6?\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>js \u5bfc\u51fa excel \u95ee\u9898\u89e3\u51b3 \u5f53\u4f7f\u7528 javascript \u5bfc\u51fa excel \u65f6\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u4e00\u6b21\u5bfc\u51fa\u591a\u4e2a\u8868\u3002\u672c\u6587\u5c06\u63a2\u8ba8\u5982\u4f55\u901a\u8fc7\u83b7\u53d6 html \u9875\u9762\u4e2d\u7684\u6570\u636e\u6765\u5b9e\u73b0\u6b64\u529f\u80fd\u3002 \u6211\u4eec\u4f7f\u7528\u7684\u662f\u57fa\u672c\u7684\u65b9\u6cd5\uff0c\u5373\u63d0\u53d6 html \u8868\u683c\u7684\u5185\u5bb9\u5e76\u5c06\u5176\u653e\u5165 excel \u4e2d\u3002\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5\u5982\u4e0b\uff1a var tabletoexcel = (function () { var uri = &#8216;data:application\/vnd.ms-excel;base64,&#8217;; var template = &#8216;&lt;html xmlns:o=&#8221;urn:schemas-microsoft-com:office:office&#8221; xmlns:x=&#8221;urn:schemas-microsoft-com:office:excel&#8221; xmlns=&#8221;http:\/\/www.w3.org\/tr\/rec-html40&#8243;&gt;&lt;head&gt;&lt;!&#8211;[if gte mso 9]&gt;&lt;xml&gt;&lt;x:excelworkbook&gt;&lt;x:excelworksheets&gt;&lt;x:excelworksheet&gt;&lt;x:name&gt;{worksheet}&lt;\/x:name&gt;&lt;x:worksheetoptions&gt;&lt;x:displaygridlines&gt;&lt;\/x:displaygridlines&gt;&lt;\/x:worksheetoptions&gt;&lt;\/x:excelworksheet&gt;&lt;\/x:excelworksheets&gt;&lt;\/x:excelworkbook&gt;&lt;\/xml&gt;&lt;![endif]&#8211;&gt;&lt;\/head&gt;&lt;body&gt;&lt;table&gt;{table}&lt;\/table&gt;&lt;\/body&gt;&lt;\/html&gt;&#8217;; var base64 = function (s) { return window.btoa(unescape(encodeuricomponent(s))) } var format = function (s, c) { return s.replace(\/{(w+)}\/g, function [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3256","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3256"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3256\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}