{"id":3476,"date":"2024-11-10T11:17:54","date_gmt":"2024-11-10T03:17:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3476\/"},"modified":"2024-11-10T11:17:54","modified_gmt":"2024-11-10T03:17:54","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-javascript-%e5%af%bc%e5%87%ba-excel-%e6%96%87%e4%bb%b6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3476\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 JavaScript \u5bfc\u51fa Excel \u6587\u4ef6\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173104293568557.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u5bfc\u51fa Excel \u6587\u4ef6\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u5bfc\u51fa Excel \u6587\u4ef6\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>js \u5bfc\u51fa excel<\/strong><\/p>\n<p><strong>\u5bfc\u51fa excel<\/strong><\/p>\n<p>\u4f7f\u7528 javascript \u5bfc\u51fa excel \u7684\u5e38\u89c1\u65b9\u6cd5\u5c31\u662f\u5c06 html \u9875\u9762\u4e2d\u7684\u6570\u636e\u63d0\u53d6\u5230 excel \u4e2d\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u53ef\u4ee5\u5229\u7528\u5982\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<pre>function tableToExcel(table, name, filename) {\n  if (!table.nodeType) table = document.getElementById(table);\n  var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML };\n  window.location.href = 'data:application\/vnd.ms-excel;base64,' + base64(format(template, ctx));\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u652f\u6301\u591a\u4e2a\u5de5\u4f5c\u8868<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u5bf9\u4e8e\u5bfc\u51fa\u591a\u4e2a\u5de5\u4f5c\u8868\u7684 excel\uff0c\u901a\u5e38\u9700\u8981\u501f\u52a9\u540e\u7aef\u6280\u672f\u3002\u53ef\u4ee5\u4f7f\u7528\u670d\u52a1\u5668\u7aef\u7684\u8bed\u8a00\u751f\u6210\u5177\u6709\u591a\u4e2a\u5de5\u4f5c\u8868\u7684 excel \u6587\u4ef6\uff0c\u7136\u540e\u5c06\u6587\u4ef6\u4f20\u9001\u7ed9\u524d\u7aef\u3002<\/p>\n<p><strong>\u5e38\u89c1\u95ee\u9898\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u5982\u4f55\u5c06\u591a\u4e2a\u8868\u683c\u5bfc\u51fa\u5230\u540c\u4e00\u5de5\u4f5c\u8868\uff1f<\/strong><\/li>\n<\/ul>\n<p>\u53ef\u4ee5\u5c06\u591a\u4e2a\u8868\u683c\u7528\u4e00\u4e2a div \u5305\u88f9\u8d77\u6765\uff0c\u7136\u540e\u901a\u8fc7 document.getelementbyid() \u83b7\u53d6 div \u7684 id\u3002<\/p>\n<ul>\n<li><strong>\u80fd\u5426\u5c06\u591a\u4e2a\u8868\u683c\u5bfc\u51fa\u5230\u4e0d\u540c\u7684\u5de5\u4f5c\u8868\u4e2d\uff1f<\/strong><\/li>\n<\/ul>\n<p>\u4e00\u822c\u6765\u8bf4\uff0c\u524d\u53f0 js \u5b9e\u73b0\u5bfc\u51fa\u5230\u4e0d\u540c\u5de5\u4f5c\u8868\u7684\u529f\u80fd\u8f83\u4e3a\u56f0\u96be\uff0c\u9700\u8981\u901a\u8fc7\u540e\u7aef\u6765\u5b9e\u73b0\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 JavaScript \u5bfc\u51fa Excel \u6587\u4ef6\uff1f\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 \u5bfc\u51fa excel \u4f7f\u7528 javascript \u5bfc\u51fa excel \u7684\u5e38\u89c1\u65b9\u6cd5\u5c31\u662f\u5c06 html \u9875\u9762\u4e2d\u7684\u6570\u636e\u63d0\u53d6\u5230 excel \u4e2d\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u53ef\u4ee5\u5229\u7528\u5982\u4e0b\u65b9\u6cd5\uff1a function tableToExcel(table, name, filename) { if (!table.nodeType) table = document.getElementById(table); var ctx = { worksheet: name || &#8216;Worksheet&#8217;, table: table.innerHTML }; window.location.href = &#8216;data:application\/vnd.ms-excel;base64,&#8217; + base64(format(template, ctx)); } \u767b\u5f55\u540e\u590d\u5236 \u652f\u6301\u591a\u4e2a\u5de5\u4f5c\u8868 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5bf9\u4e8e\u5bfc\u51fa\u591a\u4e2a\u5de5\u4f5c\u8868\u7684 excel\uff0c\u901a\u5e38\u9700\u8981\u501f\u52a9\u540e\u7aef\u6280\u672f\u3002\u53ef\u4ee5\u4f7f\u7528\u670d\u52a1\u5668\u7aef\u7684\u8bed\u8a00\u751f\u6210\u5177\u6709\u591a\u4e2a\u5de5\u4f5c\u8868\u7684 excel \u6587\u4ef6\uff0c\u7136\u540e\u5c06\u6587\u4ef6\u4f20\u9001\u7ed9\u524d\u7aef\u3002 \u5e38\u89c1\u95ee\u9898\uff1a \u5982\u4f55\u5c06\u591a\u4e2a\u8868\u683c\u5bfc\u51fa\u5230\u540c\u4e00\u5de5\u4f5c\u8868\uff1f \u53ef\u4ee5\u5c06\u591a\u4e2a\u8868\u683c\u7528\u4e00\u4e2a div \u5305\u88f9\u8d77\u6765\uff0c\u7136\u540e\u901a\u8fc7 document.getelementbyid() [&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-3476","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3476","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=3476"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3476\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}