{"id":261810,"date":"2024-05-15T14:14:40","date_gmt":"2024-05-15T06:14:40","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/261810.html"},"modified":"2024-05-15T14:14:45","modified_gmt":"2024-05-15T06:14:45","slug":"javascript-%e4%bb%a3%e7%a0%81%e5%a6%82%e4%bd%95%e5%b0%86-json-%e6%a0%bc%e5%bc%8f%e6%95%b0%e7%bb%84%e8%bd%ac%e4%b8%ba-excel-%e8%a1%a8%e6%a0%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/261810.html","title":{"rendered":"javascript \u4ee3\u7801\u5982\u4f55\u5c06 json \u683c\u5f0f\u6570\u7ec4\u8f6c\u4e3a excel \u8868\u683c"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27121320\/e9433e08-8137-4cf7-9423-a7a9879021fc.webp\" alt=\"javascript \u4ee3\u7801\u5982\u4f55\u5c06 json \u683c\u5f0f\u6570\u7ec4\u8f6c\u4e3a excel \u8868\u683c\" \/><\/p>\n<p><p>\u5c06JSON\u683c\u5f0f\u6570\u7ec4\u8f6c\u6362\u4e3aExcel\u8868\u683c\u4e3b\u8981\u901a\u8fc7\u51e0\u4e2a\u5173\u952e\u6b65\u9aa4\u5b9e\u73b0\uff1a<strong>\u5f15\u5165\u76f8\u5173\u5e93\u3001\u89e3\u6790JSON\u6570\u636e\u3001\u521b\u5efa\u5de5\u4f5c\u7c3f\u3001\u586b\u5145\u6570\u636e\u3001\u5bfc\u51fa\u4e3aExcel\u6587\u4ef6<\/strong>\u3002\u5728\u8fd9\u4e00\u7cfb\u5217\u64cd\u4f5c\u4e2d\uff0c<strong>\u5f15\u5165\u76f8\u5173\u5e93<\/strong>\u662f\u57fa\u7840\uff0c\u5b83\u4e3a\u540e\u7eed\u6240\u6709\u64cd\u4f5c\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u8981\u5f15\u5165\u4e00\u4e9b\u4e13\u95e8\u5904\u7406Excel\u6587\u4ef6\u7684JavaScript\u5e93\uff0c\u4f8b\u5982<code>xlsx<\/code>\u6216<code>exceljs<\/code>\u3002\u8fd9\u4e9b\u5e93\u63d0\u4f9b\u4e30\u5bcc\u7684API\u6765\u64cd\u4f5cExcel\u6587\u4ef6\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u521b\u5efa\u65b0\u7684\u5de5\u4f5c\u7c3f\u3001\u6dfb\u52a0\u65b0\u7684\u5de5\u4f5c\u8868\u3001\u4ee5\u53ca\u5728\u5de5\u4f5c\u8868\u4e2d\u586b\u5145\u6570\u636e\u7b49\u3002\u901a\u8fc7\u8fd9\u4e9b\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06JSON\u683c\u5f0f\u7684\u6570\u636e\u8f6c\u6362\u4e3aExcel\u8868\u683c\u3002\u5728\u8fd9\u4f17\u591a\u529f\u80fd\u4e2d\uff0c\u521b\u5efa\u5de5\u4f5c\u7c3f\u662f\u6700\u57fa\u7840\u7684\u4e00\u6b65\uff0c\u56e0\u4e3a\u6ca1\u6709\u5de5\u4f5c\u7c3f\uff0c\u5c31\u65e0\u6cd5\u6dfb\u52a0\u5de5\u4f5c\u8868\u6216\u586b\u5145\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5f15\u5165\u76f8\u5173\u5e93<\/h3>\n<\/p>\n<p><p>\u5728JavaScript\u9879\u76ee\u4e2d\uff0c\u9996\u5148\u9700\u8981\u901a\u8fc7npm\u6216yarn\u7b49\u5305\u7ba1\u7406\u5de5\u5177\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002\u8fd9\u91cc\u4ee5<code>xlsx<\/code>\u5e93\u4e3a\u4f8b\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c<code>npm install xlsx<\/code>\u6216<code>yarn add xlsx<\/code>\u547d\u4ee4\u6765\u6dfb\u52a0\u8be5\u5e93\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5c31\u53ef\u4ee5\u5728\u9879\u76ee\u4e2d\u5f15\u5165\u5e76\u4f7f\u7528\u5b83\u6765\u5904\u7406Excel\u6587\u4ef6\u4e86\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u89e3\u6790JSON\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5728\u8f6c\u6362\u6570\u636e\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u6709JSON\u683c\u5f0f\u7684\u6570\u636e\u3002\u901a\u5e38\uff0c\u8fd9\u4e9b\u6570\u636e\u53ef\u80fd\u662f\u901a\u8fc7API\u4ece\u670d\u52a1\u5668\u83b7\u53d6\u7684\uff0c\u6216\u8005\u76f4\u63a5\u5728\u4ee3\u7801\u4e2d\u5b9a\u4e49\u7684\u9759\u6001\u6570\u636e\u3002\u65e0\u8bba\u6570\u636e\u6765\u6e90\u5982\u4f55\uff0c\u90fd\u9700\u8981\u786e\u4fdd\u5b83\u662f\u6b63\u786e\u683c\u5f0f\u5316\u7684JSON\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u4ee3\u8868\u4e86Excel\u8868\u683c\u4e2d\u7684\u4e00\u884c\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u521b\u5efa\u5de5\u4f5c\u7c3f<\/h3>\n<\/p>\n<p><p>\u4e00\u65e6\u6709\u4e86\u8981\u8f6c\u6362\u7684JSON\u6570\u636e\uff0c\u4e0b\u4e00\u6b65\u5c31\u662f\u521b\u5efa\u4e00\u4e2aExcel\u5de5\u4f5c\u7c3f\u3002\u4f7f\u7528<code>xlsx<\/code>\u5e93\uff0c\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5de5\u4f5c\u7c3f\u5b9e\u4f8b\u3002\u5de5\u4f5c\u7c3f\u662f\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u5de5\u4f5c\u8868\u7684\u5bb9\u5668\uff0c\u6bcf\u4e2a\u5de5\u4f5c\u8868\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u5355\u5143\u683c\u3002\u5de5\u4f5c\u7c3f\u662fExcel\u6587\u4ef6\u7684\u9876\u5c42\u7ed3\u6784\uff0c\u662f\u6574\u4e2a\u8f6c\u6362\u8fc7\u7a0b\u7684\u57fa\u7840\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u586b\u5145\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u521b\u5efa\u5de5\u4f5c\u7c3f\u540e\uff0c\u4e0b\u4e00\u6b65\u662f\u5728\u5de5\u4f5c\u7c3f\u4e2d\u521b\u5efa\u5de5\u4f5c\u8868\uff0c\u5e76\u5c06JSON\u6570\u636e\u586b\u5145\u5230\u8fd9\u4e2a\u5de5\u4f5c\u8868\u4e2d\u3002\u4e3a\u6b64\uff0c\u53ef\u4ee5\u4f7f\u7528<code>xlsx<\/code>\u5e93\u63d0\u4f9b\u7684API\u5c06JSON\u6570\u7ec4\u8f6c\u6362\u4e3a\u5de5\u4f5c\u8868\u6240\u9700\u7684\u683c\u5f0f\uff0c\u5e76\u586b\u5145\u6570\u636e\u3002\u8fd9\u4e2a\u6b65\u9aa4\u6d89\u53ca\u5230\u628aJSON\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5de5\u4f5c\u8868\u4e2d\u7684\u4e00\u884c\uff0c\u5bf9\u8c61\u7684\u6bcf\u4e2a\u952e\u503c\u5bf9\u5e94\u5de5\u4f5c\u8868\u7684\u4e00\u5217\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5bfc\u51fa\u4e3aExcel\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u6700\u540e\u4e00\u6b65\u662f\u5c06\u586b\u5145\u5b8c\u6570\u636e\u7684\u5de5\u4f5c\u7c3f\u5bfc\u51fa\u4e3aExcel\u6587\u4ef6\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4fdd\u5b58\u5230\u670d\u52a1\u5668\u7684\u6587\u4ef6\u7cfb\u7edf\u4e0a\uff0c\u6216\u8005\u5728\u5ba2\u6237\u7aef\u76f4\u63a5\u89e6\u53d1\u6587\u4ef6\u4e0b\u8f7d\u6765\u5b9e\u73b0\u3002<code>xlsx<\/code>\u5e93\u652f\u6301\u591a\u79cd\u5bfc\u51fa\u9009\u9879\uff0c\u5305\u62ec\u8bbe\u7f6e\u6587\u4ef6\u540d\u79f0\u3001\u6307\u5b9aExcel\u6587\u4ef6\u7684\u7248\u672c\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06JSON\u683c\u5f0f\u7684\u6570\u7ec4\u8f6c\u6362\u4e3aExcel\u8868\u683c\uff0c\u5b9e\u73b0\u6570\u636e\u7684\u5feb\u901f\u4ea4\u6362\u548c\u5206\u6790\u3002\u65e0\u8bba\u662f\u7528\u4e8e\u62a5\u544a\u751f\u6210\u3001\u6570\u636e\u5206\u6790\u8fd8\u662f\u7b80\u5355\u7684\u6570\u636e\u4ea4\u6362\uff0c\u8fd9\u79cd\u8f6c\u6362\u529f\u80fd\u90fd\u975e\u5e38\u5b9e\u7528\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>Q: JavaScript\u4e2d\u5982\u4f55\u5c06json\u683c\u5f0f\u7684\u6570\u7ec4\u8f6c\u4e3aexcel\u8868\u683c\uff1f<\/strong><br \/>\nA: \u5728JavaScript\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5e93\u6216\u8005\u81ea\u5df1\u7f16\u5199\u4ee3\u7801\u6765\u5c06json\u683c\u5f0f\u7684\u6570\u7ec4\u8f6c\u4e3aexcel\u8868\u683c\u3002\u4e00\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528<code>json2xls<\/code>\u8fd9\u4e2a\u5e93\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u4f7f\u7528npm\u5b89\u88c5\u8be5\u5e93\uff0c\u7136\u540e\u5728\u4f60\u7684\u4ee3\u7801\u4e2d\u5f15\u5165\u5b83\u3002\u63a5\u4e0b\u6765\uff0c\u4f60\u9700\u8981\u5c06json\u6570\u7ec4\u8f6c\u4e3aBuffer\u5bf9\u8c61\uff0c\u7136\u540e\u4f7f\u7528<code>fs<\/code>\u6a21\u5757\u5c06\u5176\u5199\u5165\u5230excel\u6587\u4ef6\u4e2d\u3002\u6700\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u6d4f\u89c8\u5668\u4e0b\u8f7d\u8be5excel\u6587\u4ef6\u3002<\/p>\n<p><strong>Q: \u6709\u6ca1\u6709\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u5728JavaScript\u4e2d\u5c06json\u683c\u5f0f\u7684\u6570\u7ec4\u8f6c\u4e3aexcel\u8868\u683c\uff1f<\/strong><br \/>\nA: \u5f53\u7136\uff0c\u9664\u4e86\u4f7f\u7528<code>json2xls<\/code>\u5e93\u4e4b\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u5728JavaScript\u4e2d\u5c06json\u683c\u5f0f\u7684\u6570\u7ec4\u8f6c\u4e3aexcel\u8868\u683c\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>xlsx<\/code>\u8fd9\u4e2a\u5e93\u6765\u64cd\u4f5cexcel\u6587\u4ef6\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u4f7f\u7528npm\u5b89\u88c5\u8be5\u5e93\uff0c\u7136\u540e\u5728\u4f60\u7684\u4ee3\u7801\u4e2d\u5f15\u5165\u5b83\u3002\u63a5\u4e0b\u6765\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>xlsx.utils.json_to_sheet<\/code>\u65b9\u6cd5\u5c06json\u6570\u7ec4\u8f6c\u4e3asheet\u5bf9\u8c61\uff0c\u7136\u540e\u4f7f\u7528<code>xlsx.utils.book_new<\/code>\u65b9\u6cd5\u521b\u5efa\u4e00\u4e2aworkbook\u5bf9\u8c61\uff0c\u5e76\u5c06\u8be5sheet\u5bf9\u8c61\u6dfb\u52a0\u5230workbook\u4e2d\u3002\u6700\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>xlsx.writeFile<\/code>\u65b9\u6cd5\u5c06workbook\u5199\u5165\u5230excel\u6587\u4ef6\u4e2d\u3002<\/p>\n<p><strong>Q: \u9664\u4e86\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\uff0c\u6709\u6ca1\u6709\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u5728JavaScript\u4e2d\u5c06json\u683c\u5f0f\u7684\u6570\u7ec4\u8f6c\u4e3aexcel\u8868\u683c\uff1f<\/strong><br \/>\nA: \u5f53\u7136\uff0c\u9664\u4e86\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u4e4b\u5916\uff0c\u4f60\u4e5f\u53ef\u4ee5\u81ea\u5df1\u7f16\u5199\u4ee3\u7801\u6765\u5b9e\u73b0\u5728JavaScript\u4e2d\u5c06json\u683c\u5f0f\u7684\u6570\u7ec4\u8f6c\u4e3aexcel\u8868\u683c\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684excel\u6587\u4ef6\uff0c\u7136\u540e\u901a\u8fc7JavaScript\u64cd\u4f5c\u6587\u4ef6\u7684\u65b9\u5f0f\uff0c\u5c06json\u6570\u7ec4\u4e2d\u7684\u6570\u636e\u4e00\u884c\u884c\u5199\u5165\u5230excel\u6587\u4ef6\u4e2d\uff0c\u6ce8\u610f\u5728\u5199\u5165\u6570\u636e\u65f6\u9700\u8981\u5c06\u5176\u8fdb\u884c\u683c\u5f0f\u5316\uff0c\u4ee5\u6ee1\u8db3excel\u7684\u8981\u6c42\u3002\u6700\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u6d4f\u89c8\u5668\u4e0b\u8f7d\u8be5excel\u6587\u4ef6\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u597d\u5904\u662f\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u6765\u81ea\u5b9a\u4e49\u4ee3\u7801\u903b\u8f91\uff0c\u4f46\u6bd4\u8f83\u590d\u6742\uff0c\u9700\u8981\u82b1\u8d39\u8f83\u591a\u7684\u65f6\u95f4\u548c\u7cbe\u529b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5c06JSON\u683c\u5f0f\u6570\u7ec4\u8f6c\u6362\u4e3aExcel\u8868\u683c\u4e3b\u8981\u901a\u8fc7\u51e0\u4e2a\u5173\u952e\u6b65\u9aa4\u5b9e\u73b0\uff1a\u5f15\u5165\u76f8\u5173\u5e93\u3001\u89e3\u6790JSON\u6570\u636e\u3001\u521b\u5efa\u5de5\u4f5c\u7c3f\u3001\u586b\u5145 [&hellip;]","protected":false},"author":3,"featured_media":261812,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/261810"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=261810"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/261810\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/261812"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=261810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=261810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=261810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}