{"id":28049,"date":"2024-11-24T14:40:10","date_gmt":"2024-11-24T06:40:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28049\/"},"modified":"2024-11-24T14:40:10","modified_gmt":"2024-11-24T06:40:10","slug":"%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%e5%89%8d%e7%ab%af%e5%af%bc%e5%87%ba-excel-%e6%96%87%e4%bb%b6%e6%97%b6%e5%8d%95%e5%85%83%e6%a0%bc%e6%a0%b7%e5%bc%8f%e6%97%a0%e6%b3%95%e4%bf%9d%e6%8c%81%e7%9a%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28049\/","title":{"rendered":"\u5982\u4f55\u89e3\u51b3\u524d\u7aef\u5bfc\u51fa Excel \u6587\u4ef6\u65f6\u5355\u5143\u683c\u6837\u5f0f\u65e0\u6cd5\u4fdd\u6301\u7684\u95ee\u9898\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173138577962902.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u89e3\u51b3\u524d\u7aef\u5bfc\u51fa Excel \u6587\u4ef6\u65f6\u5355\u5143\u683c\u6837\u5f0f\u65e0\u6cd5\u4fdd\u6301\u7684\u95ee\u9898\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u89e3\u51b3\u524d\u7aef\u5bfc\u51fa Excel \u6587\u4ef6\u65f6\u5355\u5143\u683c\u6837\u5f0f\u65e0\u6cd5\u4fdd\u6301\u7684\u95ee\u9898\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u89e3\u51b3\u524d\u7aef\u5bfc\u51fa excel \u65e0\u5355\u5143\u683c\u95ee\u9898<\/strong><\/p>\n<p>\u5728\u524d\u7aef\u5f00\u53d1\u4e2d\uff0c\u5c06\u6570\u636e\u5bfc\u51fa\u4e3a Excel \u683c\u5f0f\u7684\u9700\u6c42\u5f88\u5e38\u89c1\u3002\u7136\u800c\uff0c\u4f20\u7edf\u7684\u5bfc\u51fa\u65b9\u6cd5\u5f80\u5f80\u65e0\u6cd5\u6ee1\u8db3\u7279\u6b8a\u6837\u5f0f\u9700\u6c42\u3002\u4e3a\u6b64\uff0c\u5f00\u53d1\u8005\u5c1d\u8bd5\u5c01\u88c5\u4e86\u4e00\u4e2a\u5bfc\u51fa Excel \u7684\u5de5\u5177\u3002<\/p>\n<p><strong>\u5c01\u88c5\u601d\u8def\uff1a<\/strong><\/p>\n<p>\u8fd9\u4e2a\u5de5\u5177\u5c06 Excel \u4e0e\u8868\u683c\u5173\u8054\u8d77\u6765\uff0c\u5229\u7528 new Blob() \u6784\u9020\u51fd\u6570\u4f5c\u4e3a\u6865\u6881\u3002\u901a\u8fc7\u83b7\u53d6\u8868\u683c\u7684 DOM \u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a Blob \u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a Excel \u6587\u4ef6\u3002<\/p>\n<p><strong>\u5c1d\u8bd5\u7ed3\u679c\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u8be5\u5de5\u5177\u53ef\u4ee5\u751f\u6210 Excel \u6587\u4ef6\uff0c\u4f46\u6837\u5f0f\u5b58\u5728\u7f3a\u9677\uff0c\u65b0\u589e\u884c\u6216\u5217\u4f1a\u5f71\u54cd\u6837\u5f0f\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u5355\u5143\u683c\u4e0d\u53ef\u7f16\u8f91\u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 ExcelJS \u5e93\u3002ExcelJS \u662f\u4e00\u6b3e\u529f\u80fd\u5f3a\u5927\u7684 Excel JS \u5e93\uff0c\u63d0\u4f9b\u4e30\u5bcc\u7684\u6837\u5f0f\u5b9a\u5236\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 ExcelJS \u5bfc\u51fa Excel \u6587\u4ef6\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>const Excel = require('exceljs');\n\n\/\/ \u521b\u5efa\u4e00\u4e2a\u5de5\u4f5c\u7c3f\nconst workbook = new Excel.Workbook();\n\n\/\/ \u6dfb\u52a0\u4e00\u4e2a\u5de5\u4f5c\u8868\nconst worksheet = workbook.addWorksheet('Sheet1');\n\n\/\/ \u6dfb\u52a0\u6570\u636e\nworksheet.getCell('A1').value = '\u59d3\u540d';\nworksheet.getCell('B1').value = '\u5e74\u9f84';\nworksheet.getCell('C1').value = '\u804c\u4f4d';\nworksheet.getCell('A2').value = '\u5f20\u4e09';\nworksheet.getCell('B2').value = 28;\nworksheet.getCell('C2').value = '\u5de5\u7a0b\u5e08';\n\n\/\/ \u8bbe\u7f6e\u5355\u5143\u683c\u8fb9\u6846\nworksheet.getCell('A1').border = {\n  top: {style:'thin'},\n  left: {style:'thin'},\n  bottom: {style:'thin'},\n  right: {style:'thin'}\n};\n\n\/\/ \u8bbe\u7f6e\u5355\u5143\u683c\u586b\u5145\u8272\nworksheet.getCell('A1').fill = {\n  type: 'pattern',\n  pattern: 'solid',\n  fgColor: {argb:'FF00FF00'}\n};\n\n\/\/ \u4fdd\u5b58\u6587\u4ef6\nworkbook.xlsx.writeFile('test.xlsx');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528 ExcelJS\uff0c\u6211\u4eec\u53ef\u4ee5\u81ea\u5b9a\u4e49\u5355\u5143\u683c\u6837\u5f0f\uff0c\u5e76\u4fdd\u6301\u5355\u5143\u683c\u7684\u53ef\u7f16\u8f91\u6027\u3002\u56e0\u6b64\uff0c\u5b83\u662f\u4e00\u4e2a\u5bfc\u51fa\u53ef\u7f16\u8f91 Excel \u6587\u4ef6\u7684 excellent \u9009\u62e9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u89e3\u51b3\u524d\u7aef\u5bfc\u51fa Excel \u6587\u4ef6\u65f6\u5355\u5143\u683c\u6837\u5f0f\u65e0\u6cd5\u4fdd\u6301\u7684\u95ee\u9898\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>\u89e3\u51b3\u524d\u7aef\u5bfc\u51fa excel \u65e0\u5355\u5143\u683c\u95ee\u9898 \u5728\u524d\u7aef\u5f00\u53d1\u4e2d\uff0c\u5c06\u6570\u636e\u5bfc\u51fa\u4e3a Excel \u683c\u5f0f\u7684\u9700\u6c42\u5f88\u5e38\u89c1\u3002\u7136\u800c\uff0c\u4f20\u7edf\u7684\u5bfc\u51fa\u65b9\u6cd5\u5f80\u5f80\u65e0\u6cd5\u6ee1\u8db3\u7279\u6b8a\u6837\u5f0f\u9700\u6c42\u3002\u4e3a\u6b64\uff0c\u5f00\u53d1\u8005\u5c1d\u8bd5\u5c01\u88c5\u4e86\u4e00\u4e2a\u5bfc\u51fa Excel \u7684\u5de5\u5177\u3002 \u5c01\u88c5\u601d\u8def\uff1a \u8fd9\u4e2a\u5de5\u5177\u5c06 Excel \u4e0e\u8868\u683c\u5173\u8054\u8d77\u6765\uff0c\u5229\u7528 new Blob() \u6784\u9020\u51fd\u6570\u4f5c\u4e3a\u6865\u6881\u3002\u901a\u8fc7\u83b7\u53d6\u8868\u683c\u7684 DOM \u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a Blob \u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a Excel \u6587\u4ef6\u3002 \u5c1d\u8bd5\u7ed3\u679c\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u8be5\u5de5\u5177\u53ef\u4ee5\u751f\u6210 Excel \u6587\u4ef6\uff0c\u4f46\u6837\u5f0f\u5b58\u5728\u7f3a\u9677\uff0c\u65b0\u589e\u884c\u6216\u5217\u4f1a\u5f71\u54cd\u6837\u5f0f\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u4e3a\u4e86\u89e3\u51b3\u5355\u5143\u683c\u4e0d\u53ef\u7f16\u8f91\u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 ExcelJS \u5e93\u3002ExcelJS \u662f\u4e00\u6b3e\u529f\u80fd\u5f3a\u5927\u7684 Excel JS \u5e93\uff0c\u63d0\u4f9b\u4e30\u5bcc\u7684\u6837\u5f0f\u5b9a\u5236\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 ExcelJS \u5bfc\u51fa Excel \u6587\u4ef6\u7684\u793a\u4f8b\uff1a const Excel = require(&#8216;exceljs&#8217;); \/\/ \u521b\u5efa\u4e00\u4e2a\u5de5\u4f5c\u7c3f const workbook = new Excel.Workbook(); \/\/ \u6dfb\u52a0\u4e00\u4e2a\u5de5\u4f5c\u8868 const worksheet = workbook.addWorksheet(&#8216;Sheet1&#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-28049","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28049","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=28049"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28049\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}