{"id":1606,"date":"2022-10-21T13:18:58","date_gmt":"2022-10-21T05:18:58","guid":{"rendered":"https:\/\/zhuxinyong.com\/?p=1606"},"modified":"2022-10-26T11:25:42","modified_gmt":"2022-10-26T03:25:42","slug":"json-dao-chu-wei-excel","status":"publish","type":"post","link":"https:\/\/zhuxinyong.com\/?p=1606","title":{"rendered":"JSON \u5bfc\u51fa\u4e3a Excel"},"content":{"rendered":"<p>JSON \u6570\u636e\u5bfc\u51fa Excel \u6587\u4ef6\u9700\u8981\u501f\u52a9 <a href=\"https:\/\/github.com\/SheetJS\/sheetjs\" target=\"_blank\" rel=\"noopener\">SheetJS<\/a> \u8fd9\u4e2a\u5f00\u6e90\u5e93\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/10\/16665361031960.jpg\" alt=\"\" \/><\/p>\n<h3><a id=\"html%E8%A1%A8%E6%A0%BC%E5%AF%BC%E5%87%BA%E4%B8%BA-excel%E6%96%87%E4%BB%B6\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>HTML \u8868\u683c\u5bfc\u51fa\u4e3a Excel \u6587\u4ef6<\/h3>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">&lt;!-- \u6587\u4ef6\u4e2d\u5f15\u5165\u811a\u672c--&gt;\n&lt;script src=&quot;https:\/\/cdn.sheetjs.com\/xlsx-latest\/package\/dist\/xlsx.full.min.js&quot;&gt;&lt;\/script&gt;\n\n&lt;!--\u8868\u683c--&gt;\n&lt;table id=&quot;TableToExport&quot;&gt;\n\n&lt;!--\u5bfc\u51fa\u6309\u94ae--&gt;\n&lt;button id=&quot;sheetjsexport&quot;&gt;&lt;b&gt;Export as XLSX&lt;\/b&gt;&lt;\/button&gt;\n\n\n&lt;script&gt;\ndocument.getElementById(&quot;sheetjsexport&quot;).addEventListener('click', function() {\n  \/* Create worksheet from HTML DOM TABLE *\/\n  var wb = XLSX.utils.table_to_book(document.getElementById(&quot;TableToExport&quot;));\n  \/* Export to file (start a download) *\/\n  XLSX.writeFile(wb, &quot;SheetJSTable.xlsx&quot;);\n});\n&lt;\/script&gt;\n<\/code><\/pre>\n<p><iframe height=\"300\" style=\"width: 100%;\" scrolling=\"no\" title=\"download-excel-XLSX\" src=\"https:\/\/codepen.io\/ghostcode\/embed\/WNJVNqM?default-tab=html%2Cresult\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"><br \/>\n  See the Pen <a href=\"https:\/\/codepen.io\/ghostcode\/pen\/WNJVNqM\" target=\"_blank\" rel=\"noopener\"><br \/>\n  download-excel-XLSX<\/a> by ghostcode (<a href=\"https:\/\/codepen.io\/ghostcode\" target=\"_blank\" rel=\"noopener\">@ghostcode<\/a>)<br \/>\n  on <a href=\"https:\/\/codepen.io\" target=\"_blank\" rel=\"noopener\">CodePen<\/a>.<br \/>\n<\/iframe><\/p>\n<p>\u6ce8\u610f\uff1a<\/p>\n<ol>\n<li>\u9009\u62e9\u7684\u5143\u7d20\u5fc5\u987b\u4e3a Table \u5426\u5219\u4f1a\u62a5\u9519\u3002<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/10\/16667481157928.jpg\" alt=\"\" \/><\/p>\n<ol start=\"2\">\n<li>\u5982\u679c\u662f UI \u5e93\u751f\u6210\u7684\u8868\u683c\uff0c\u8981\u7279\u522b\u6ce8\u610f\u5b9e\u9645\u7684 HMLT \u5e76\u4e0d\u662f\u4e00\u4e2a Table:<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/10\/16667482250432.jpg\" alt=\"\" \/><\/p>\n<p>\u6240\u4ee5\u5728\u5bfc\u51fa\u7684\u65f6\u5019\uff0c\u53ef\u80fd\u53ea\u6709\u6807\u9898\u6ca1\u6709\u6570\u636e\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/10\/16667482924510.jpg\" alt=\"\" \/><\/p>\n<p>\u89e3\u51b3\u65b9\u6848\u662f\uff1a\u62fc\u63a5\u4e24\u4e2a\u8868\u683c\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">const exportTableWrap = document.querySelector(&quot;.export-table&quot;);\nconst tables = exportTableWrap.querySelectorAll('.ant-table-fixed')\nconst ws = XLSX.utils.table_to_sheet(tables[0]);\n\nXLSX.utils.sheet_add_dom(ws,tables[1],{\norigin:-1,\n})\n\nconst wb = XLSX.utils.book_new()\nXLSX.utils.book_append_sheet(wb,ws)\nXLSX.writeFile(wb, &quot;\u7edf\u8ba1\u5206\u6790.xlsx&quot;)\n<\/code><\/pre>\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/docs.sheetjs.com\/docs\/api\/utilities#html-table-input\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.sheetjs.com\/docs\/api\/utilities#html-table-input<\/a><\/p>\n<p>\u4e0b\u8f7d\u7684\u8868\u683c\u6b63\u786e\uff0c\u4f46\u662f\u65e5\u671f\u90a3\u4e00\u5217\u51fa\u95ee\u9898\u4e86\u3002\u7531\u4e8e\u592a\u7a84\u5bfc\u81f4\u65e5\u671f\u4e0d\u663e\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/10\/16667526071260.jpg\" alt=\"\" \/><\/p>\n<p>\u89e3\u51b3\uff1a\u8bbe\u7f6e\u5217\u5bbd\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/10\/16667527628871.jpg\" alt=\"\" \/><\/p>\n<p>\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/10\/16667528018190.jpg\" alt=\"\" \/><\/p>\n<p>\u53c2\u8003\uff1a<\/p>\n<ol>\n<li><a href=\"https:\/\/docs.sheetjs.com\/docs\/csf\/features\/#row-and-column-properties\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.sheetjs.com\/docs\/csf\/features\/#row-and-column-properties<\/a><\/li>\n<li><a href=\"https:\/\/docs.sheetjs.com\/docs\/getting-started\/example#clean-up-workbook\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.sheetjs.com\/docs\/getting-started\/example#clean-up-workbook<\/a><\/li>\n<li><a href=\"https:\/\/blog.csdn.net\/a843334549\/article\/details\/114651578\" target=\"_blank\" rel=\"noopener\">https:\/\/blog.csdn.net\/a843334549\/article\/details\/114651578<\/a><\/li>\n<li><a href=\"https:\/\/www.jianshu.com\/p\/e2cd2cb28ba9\" target=\"_blank\" rel=\"noopener\">https:\/\/www.jianshu.com\/p\/e2cd2cb28ba9<\/a><\/li>\n<\/ol>\n<h3><a id=\"json%E6%95%B0%E6%8D%AE%E5%AF%BC%E5%87%BA-excel%E6%96%87%E4%BB%B6\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>JSON \u6570\u636e\u5bfc\u51fa Excel \u6587\u4ef6<\/h3>\n<p><iframe height=\"300\" style=\"width: 100%;\" scrolling=\"no\" title=\"export-json-to-excel-XLSX\" src=\"https:\/\/codepen.io\/ghostcode\/embed\/GRdVgjE?default-tab=html%2Cresult\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"><br \/>\n  See the Pen <a href=\"https:\/\/codepen.io\/ghostcode\/pen\/GRdVgjE\" target=\"_blank\" rel=\"noopener\"><br \/>\n  export-json-to-excel-XLSX<\/a> by ghostcode (<a href=\"https:\/\/codepen.io\/ghostcode\" target=\"_blank\" rel=\"noopener\">@ghostcode<\/a>)<br \/>\n  on <a href=\"https:\/\/codepen.io\" target=\"_blank\" rel=\"noopener\">CodePen<\/a>.<br \/>\n<\/iframe><\/p>\n<p>\u53c2\u8003\uff1a<\/p>\n<ol>\n<li><a href=\"https:\/\/docs.sheetjs.com\/docs\/getting-started\/example\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.sheetjs.com\/docs\/getting-started\/example<\/a><\/li>\n<li><a href=\"https:\/\/blog.csdn.net\/weixin_41897680\/article\/details\/123109969\" target=\"_blank\" rel=\"noopener\">https:\/\/blog.csdn.net\/weixin_41897680\/article\/details\/123109969<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>JSON \u6570\u636e\u5bfc\u51fa Excel \u6587\u4ef6\u9700\u8981\u501f\u52a9 SheetJS \u8fd9\u4e2a\u5f00\u6e90\u5e93\u3002 HTML \u8868\u683c\u5bfc\u51fa\u4e3a E&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,20,3],"tags":[50,233],"class_list":["post-1606","post","type-post","status-publish","format-standard","hentry","category-all","category-frontend","category-tech","tag-excel","tag-sheetjs"],"_links":{"self":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1606"}],"version-history":[{"count":2,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1606\/revisions"}],"predecessor-version":[{"id":1614,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1606\/revisions\/1614"}],"wp:attachment":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}