{"id":206471,"date":"2025-06-12T12:26:00","date_gmt":"2025-06-12T04:26:00","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206471\/"},"modified":"2025-06-12T12:26:00","modified_gmt":"2025-06-12T04:26:00","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8go%e8%af%ad%e8%a8%80%e8%a7%a3%e6%9e%90xml%e6%95%b0%e6%8d%ae%e4%b8%ad%e5%ad%98%e5%82%a8%e7%9a%84excel-worksheet%e7%bb%93%e6%9e%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206471\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Go\u8bed\u8a00\u89e3\u6790XML\u6570\u636e\u4e2d\u5b58\u50a8\u7684Excel Worksheet\u7ed3\u6784\uff1f"},"content":{"rendered":"<p>GOLANG\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528Go\u8bed\u8a00\u89e3\u6790XML\u6570\u636e\u4e2d\u5b58\u50a8\u7684Excel Worksheet\u7ed3\u6784\uff1f\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241112\/1731413367673345778f2dd.jpg\" class=\"aligncenter\">,<br \/>\n<strong>\u5173\u4e8ego\u8bfb\u53d6xml\u4e2dworksheet\u7684\u95ee\u9898<\/strong>,\u95ee\u9898\uff1a\u5982\u4f55\u6b63\u786e\u63d0\u53d6go\u4e2dxml\u6570\u636e\u4e2d\u5b58\u50a8\u7684excel worksheet\u7ed3\u6784\uff1f,<br \/>\n<strong>\u7b54\u6848\uff1a<\/strong>,\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6\u5e93 encoding\/xml \u89e3\u6790xml\u5e76\u63d0\u53d6worksheet\u6570\u636e\u3002,<br \/>\n<strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong>,<br \/>\n<strong>\u8981\u70b9\uff1a<\/strong>,\u8bf7\u6ce8\u610f\uff0c\u63d0\u4f9b\u7684\u4ee3\u7801\u4ec5\u5c55\u793a\u4e86\u57fa\u672c\u7684\u5de5\u4f5c\u539f\u7406\u3002\u5b9e\u9645\u5b9e\u73b0\u53ef\u80fd\u9700\u8981\u9488\u5bf9\u5177\u4f53\u7528\u4f8b\u8fdb\u884c\u8c03\u6574\u548c\u6269\u5c55\u3002,\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u5982\u4f55\u4f7f\u7528Go\u8bed\u8a00\u89e3\u6790XML\u6570\u636e\u4e2d\u5b58\u50a8\u7684Excel Worksheet\u7ed3\u6784\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591aGOLANG\u77e5\u8bc6\uff01,worksheet \u7ed3\u6784\u8868\u793a\u5de5\u4f5c\u8868\u6570\u636e\u7684xml\u7ed3\u6784\u3002,\u4f7f\u7528 encoding\/xml \u5305\u7684 unmarshal \u51fd\u6570\u89e3\u6790xml\u5e76\u5c06\u5176\u89e3\u7ec4\u5230 workbook \u7ed3\u6784\u4e2d\u3002,table\u3001row \u548c cell \u7b49\u7ed3\u6784\u8868\u793a\u8868\u3001\u884c\u548c\u5355\u5143\u683c\u7684xml\u7ed3\u6784\u3002,\u5173\u4e8ego\u8bfb\u53d6xml\u4e2dworksheet\u7684\u95ee\u9898,GOLANG\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528Go\u8bed\u8a00\u89e3\u6790XML\u6570\u636e\u4e2d\u5b58\u50a8\u7684Excel Worksheet\u7ed3\u6784\uff1f\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01,<br \/>\n<b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u5982\u4f55\u4f7f\u7528Go\u8bed\u8a00\u89e3\u6790XML\u6570\u636e\u4e2d\u5b58\u50a8\u7684Excel Worksheet\u7ed3\u6784\uff1f<\/span><\/p>\n<h1>\u5982\u4f55\u4f7f\u7528Go\u8bed\u8a00\u89e3\u6790XML\u6570\u636e\u4e2d\u5b58\u50a8\u7684Excel Worksheet\u7ed3\u6784\uff1f<\/h1>\n<p><span>2024-11-12 20:09:43<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>GOLANG\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528Go\u8bed\u8a00\u89e3\u6790XML\u6570\u636e\u4e2d\u5b58\u50a8\u7684Excel Worksheet\u7ed3\u6784\uff1f\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241112\/1731413367673345778f2dd.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5173\u4e8ego\u8bfb\u53d6xml\u4e2dworksheet\u7684\u95ee\u9898<\/strong><\/p>\n<p>\u95ee\u9898\uff1a\u5982\u4f55\u6b63\u786e\u63d0\u53d6go\u4e2dxml\u6570\u636e\u4e2d\u5b58\u50a8\u7684excel worksheet\u7ed3\u6784\uff1f<\/p>\n<p><strong>\u7b54\u6848\uff1a<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6\u5e93 encoding\/xml \u89e3\u6790xml\u5e76\u63d0\u53d6worksheet\u6570\u636e\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>package main\n\nimport (\n    \"encoding\/xml\"\n    \"fmt\"\n)\n\n\/\/ Workbook represents the XML structure of an Excel workbook.\ntype Workbook struct {\n    Worksheet Worksheet `xml:\"Worksheet\"`\n}\n\n\/\/ Worksheet represents the XML structure of a worksheet.\ntype Worksheet struct {\n    Table Table `xml:\"Table\"`\n}\n\n\/\/ Table represents the XML structure of a table within a worksheet.\ntype Table struct {\n    Rows []Row `xml:\"Row\"`\n}\n\n\/\/ Row represents the XML structure of a row within a table.\ntype Row struct {\n    Cells []Cell `xml:\"Cell\"`\n}\n\n\/\/ Cell represents the XML structure of a cell within a row.\ntype Cell struct {\n    Value string `xml:\"Data\"`\n}\n\nfunc main() {\n    var book Workbook\n    err := xml.Unmarshal([]byte(xmldata), &amp;book)\n    if err != nil {\n        fmt.Println(err)\n        return\n    }\n\n    \/\/ Access the worksheet data\n    for _, row := range book.Worksheet.Table.Rows {\n        for _, cell := range row.Cells {\n            fmt.Println(cell.Value)\n        }\n    }\n}\n\n\/\/ Sample XML data representing an Excel worksheet\nvar xmldata = `\n&lt;?xml version=\"1.0\"?&gt;\n&lt;?mso-application progid=\"Excel.Sheet\"?&gt;\n&lt;Workbook\n    xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\n    xmlns:o=\"urn:schemas-microsoft-com:office:office\"\n    xmlns:x=\"urn:schemas-microsoft-com:office:excel\"\n    xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\"&gt;\n    &lt;Worksheet ss:Name=\"Sheet\"&gt;\n        &lt;Table&gt;\n            &lt;Row&gt;\n                &lt;Cell&gt;&lt;Data&gt;Column 1&lt;\/Data&gt;&lt;\/Cell&gt;\n                &lt;Cell&gt;&lt;Data&gt;Column 2&lt;\/Data&gt;&lt;\/Cell&gt;\n                &lt;Cell&gt;&lt;Data&gt;Column 3&lt;\/Data&gt;&lt;\/Cell&gt;\n            &lt;\/Row&gt;\n            &lt;Row&gt;\n                &lt;Cell&gt;&lt;Data&gt;Row 2, Column 1&lt;\/Data&gt;&lt;\/Cell&gt;\n                &lt;Cell&gt;&lt;Data&gt;Row 2, Column 2&lt;\/Data&gt;&lt;\/Cell&gt;\n                &lt;Cell&gt;&lt;Data&gt;Row 2, Column 3&lt;\/Data&gt;&lt;\/Cell&gt;\n            &lt;\/Row&gt;\n        &lt;\/Table&gt;\n    &lt;\/Worksheet&gt;\n&lt;\/Workbook&gt;`<\/pre>\n<p><strong>\u8981\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 encoding\/xml \u5305\u7684 unmarshal \u51fd\u6570\u89e3\u6790xml\u5e76\u5c06\u5176\u89e3\u7ec4\u5230 workbook \u7ed3\u6784\u4e2d\u3002<\/li>\n<li>worksheet \u7ed3\u6784\u8868\u793a\u5de5\u4f5c\u8868\u6570\u636e\u7684xml\u7ed3\u6784\u3002<\/li>\n<li>table\u3001row \u548c cell \u7b49\u7ed3\u6784\u8868\u793a\u8868\u3001\u884c\u548c\u5355\u5143\u683c\u7684xml\u7ed3\u6784\u3002<\/li>\n<li>\u89e3\u7ec4\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u8bbf\u95ee\u548c\u5904\u7406\u5de5\u4f5c\u8868\u6570\u636e\u3002<\/li>\n<\/ul>\n<p>\u8bf7\u6ce8\u610f\uff0c\u63d0\u4f9b\u7684\u4ee3\u7801\u4ec5\u5c55\u793a\u4e86\u57fa\u672c\u7684\u5de5\u4f5c\u539f\u7406\u3002\u5b9e\u9645\u5b9e\u73b0\u53ef\u80fd\u9700\u8981\u9488\u5bf9\u5177\u4f53\u7528\u4f8b\u8fdb\u884c\u8c03\u6574\u548c\u6269\u5c55\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u5982\u4f55\u4f7f\u7528Go\u8bed\u8a00\u89e3\u6790XML\u6570\u636e\u4e2d\u5b58\u50a8\u7684Excel Worksheet\u7ed3\u6784\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591aGOLANG\u77e5\u8bc6\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u5982\u4f55\u5c06\u84dd\u6e56\u8bbe\u8ba1\u7a3f\u9ad8\u6548\u8f6c\u5316\u4e3a\u4ee3\u7801\uff1f\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   PHP\u5982\u4f55\u83b7\u53d6\u4e0a\u4f20\u9875\u9762\u4e2ddiv\u7684\u5185\u5bb9\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>GOLANG\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765 \u300a&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-206471","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=206471"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206471\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}