{"id":27994,"date":"2024-11-24T13:14:19","date_gmt":"2024-11-24T05:14:19","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27994\/"},"modified":"2024-11-24T13:14:19","modified_gmt":"2024-11-24T05:14:19","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-exceljs-%e5%af%bc%e5%87%ba%e5%8f%af%e7%bc%96%e8%be%91%e7%9a%84-excel-%e6%96%87%e4%bb%b6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27994\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 ExcelJS \u5bfc\u51fa\u53ef\u7f16\u8f91\u7684 Excel \u6587\u4ef6\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173137645272829.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 ExcelJS \u5bfc\u51fa\u53ef\u7f16\u8f91\u7684 Excel \u6587\u4ef6\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 ExcelJS \u5bfc\u51fa\u53ef\u7f16\u8f91\u7684 Excel \u6587\u4ef6\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u751f\u6210 excel \u6587\u4ef6\u540e\u5355\u5143\u683c\u4e0d\u53ef\u7f16\u8f91<\/strong><\/p>\n<p>\u5728\u524d\u7aef\u5f00\u53d1\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u5bfc\u51fa\u6570\u636e\u5230 Excel \u683c\u5f0f\u3002\u65b0 Blob() \u6784\u9020\u51fd\u6570\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06 table \u8f6c\u6362\u6210 Excel \u6587\u4ef6\uff0c\u4f46\u662f\u751f\u6210\u7684 Excel \u6587\u4ef6\u5374\u65e0\u6cd5\u7f16\u8f91\uff0c\u5355\u5143\u683c\u6837\u5f0f\u4f1a\u9519\u4e71\u3002<\/p>\n<p>\u60f3\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u63a8\u8350\u4f7f\u7528 <strong>ExcelJS<\/strong> \u5e93\u3002ExcelJS \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u524d\u7aef Excel \u5e93\uff0c\u53ef\u4ee5\u8f7b\u677e\u5b9a\u5236\u5355\u5143\u683c\u6837\u5f0f\u5e76\u4fdd\u5b58\u4e3a\u53ef\u7f16\u8f91\u7684 Excel \u6587\u4ef6\u3002<\/p>\n<p>\u9664\u4e86\u5bfc\u51fa Excel \u6587\u4ef6\uff0cExcelJS \u8fd8\u652f\u6301\u4ee5\u4e0b\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>\u521b\u5efa\u548c\u7f16\u8f91\u5de5\u4f5c\u7c3f\u3001\u5de5\u4f5c\u8868\u548c\u5355\u5143\u683c<\/li>\n<li>\u8bbe\u7f6e\u5355\u5143\u683c\u503c\u3001\u683c\u5f0f\u548c\u6837\u5f0f<\/li>\n<li>\u5408\u5e76\u5355\u5143\u683c\u3001\u6dfb\u52a0\u6ce8\u91ca\u548c\u56fe\u50cf<\/li>\n<li>\u4fdd\u62a4\u5de5\u4f5c\u7c3f\u548c\u5de5\u4f5c\u8868<\/li>\n<li>\u4f7f\u7528\u63d2\u4ef6\u6269\u5c55\u529f\u80fd<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528 ExcelJS \u5bfc\u51fa\u53ef\u7f16\u8f91 Excel \u6587\u4ef6\u7684\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>const ExcelJS = require('exceljs');\n\n\/\/ \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5de5\u4f5c\u7c3f\nconst workbook = new ExcelJS.Workbook();\n\n\/\/ \u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u5de5\u4f5c\u8868\nconst worksheet = workbook.addWorksheet('My Sheet');\n\n\/\/ \u8bbe\u7f6e\u5355\u5143\u683c\u503c\u548c\u6837\u5f0f\nworksheet.getCell('A1').value = '\u503c';\nworksheet.getCell('A1').font = { name: 'Arial', size: 12 };\n\n\/\/ \u4fdd\u5b58\u5230 Excel \u6587\u4ef6\nworkbook.xlsx.writeFile('test.xlsx');<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4f7f\u7528 ExcelJS\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5bfc\u51fa\u53ef\u7f16\u8f91\u7684 Excel \u6587\u4ef6\uff0c\u6ee1\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 ExcelJS \u5bfc\u51fa\u53ef\u7f16\u8f91\u7684 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>\u751f\u6210 excel \u6587\u4ef6\u540e\u5355\u5143\u683c\u4e0d\u53ef\u7f16\u8f91 \u5728\u524d\u7aef\u5f00\u53d1\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u5bfc\u51fa\u6570\u636e\u5230 Excel \u683c\u5f0f\u3002\u65b0 Blob() \u6784\u9020\u51fd\u6570\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06 table \u8f6c\u6362\u6210 Excel \u6587\u4ef6\uff0c\u4f46\u662f\u751f\u6210\u7684 Excel \u6587\u4ef6\u5374\u65e0\u6cd5\u7f16\u8f91\uff0c\u5355\u5143\u683c\u6837\u5f0f\u4f1a\u9519\u4e71\u3002 \u60f3\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u63a8\u8350\u4f7f\u7528 ExcelJS \u5e93\u3002ExcelJS \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u524d\u7aef Excel \u5e93\uff0c\u53ef\u4ee5\u8f7b\u677e\u5b9a\u5236\u5355\u5143\u683c\u6837\u5f0f\u5e76\u4fdd\u5b58\u4e3a\u53ef\u7f16\u8f91\u7684 Excel \u6587\u4ef6\u3002 \u9664\u4e86\u5bfc\u51fa Excel \u6587\u4ef6\uff0cExcelJS \u8fd8\u652f\u6301\u4ee5\u4e0b\u529f\u80fd\uff1a \u521b\u5efa\u548c\u7f16\u8f91\u5de5\u4f5c\u7c3f\u3001\u5de5\u4f5c\u8868\u548c\u5355\u5143\u683c \u8bbe\u7f6e\u5355\u5143\u683c\u503c\u3001\u683c\u5f0f\u548c\u6837\u5f0f \u5408\u5e76\u5355\u5143\u683c\u3001\u6dfb\u52a0\u6ce8\u91ca\u548c\u56fe\u50cf \u4fdd\u62a4\u5de5\u4f5c\u7c3f\u548c\u5de5\u4f5c\u8868 \u4f7f\u7528\u63d2\u4ef6\u6269\u5c55\u529f\u80fd \u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528 ExcelJS \u5bfc\u51fa\u53ef\u7f16\u8f91 Excel \u6587\u4ef6\u7684\u4ee3\u7801\u793a\u4f8b\uff1a const ExcelJS = require(&#8216;exceljs&#8217;); \/\/ \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5de5\u4f5c\u7c3f const workbook = new ExcelJS.Workbook(); \/\/ \u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u5de5\u4f5c\u8868 const worksheet = workbook.addWorksheet(&#8216;My Sheet&#8217;); \/\/ [&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-27994","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27994","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=27994"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27994\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}