{"id":206272,"date":"2025-06-12T10:10:02","date_gmt":"2025-06-12T02:10:02","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206272\/"},"modified":"2025-06-12T10:10:02","modified_gmt":"2025-06-12T02:10:02","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%e5%b9%b6%e6%8f%90%e5%8f%96excel-worksheet%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206272\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Go\u8bed\u8a00\u89e3\u6790XML\u6570\u636e\u5e76\u63d0\u53d6Excel Worksheet\u4e2d\u7684\u6570\u636e\uff1f"},"content":{"rendered":"<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<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\u5e76\u63d0\u53d6Excel Worksheet\u4e2d\u7684\u6570\u636e\uff1f\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728GOLANG\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241108\/1731034279672d7ca71b96e.jpg\" class=\"aligncenter\">,\u5173\u4e8ego\u8bfb\u53d6xml\u4e2dworksheet\u7684\u95ee\u9898,\u4e3a\u4e86\u6b63\u786e\u63d0\u53d6excel\u4e2dworksheet\u7ed3\u6784\u5185\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6\u5e93encoding\/xml\u8fdb\u884c\u89e3\u6790\u3002\u89e3\u6790\u7684\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a,\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8eGOLANG\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~,\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<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\u5e76\u63d0\u53d6Excel Worksheet\u4e2d\u7684\u6570\u636e\uff1f\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728GOLANG\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\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\u5e76\u63d0\u53d6Excel Worksheet\u4e2d\u7684\u6570\u636e\uff1f<\/span><\/p>\n<h1>\u5982\u4f55\u4f7f\u7528Go\u8bed\u8a00\u89e3\u6790XML\u6570\u636e\u5e76\u63d0\u53d6Excel Worksheet\u4e2d\u7684\u6570\u636e\uff1f<\/h1>\n<p><span>2024-11-08 10:51:34<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<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\u5e76\u63d0\u53d6Excel Worksheet\u4e2d\u7684\u6570\u636e\uff1f\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728GOLANG\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241108\/1731034279672d7ca71b96e.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5173\u4e8ego\u8bfb\u53d6xml\u4e2dworksheet\u7684\u95ee\u9898<\/p>\n<p>\u4e3a\u4e86\u6b63\u786e\u63d0\u53d6excel\u4e2dworksheet\u7ed3\u6784\u5185\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6\u5e93encoding\/xml\u8fdb\u884c\u89e3\u6790\u3002\u89e3\u6790\u7684\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u5b9a\u4e49\u4e0exml\u7ed3\u6784\u76f8\u5bf9\u5e94\u7684go\u7ed3\u6784\u4f53\u3002<\/li>\n<li>\u4f7f\u7528xml.unmarshal()\u51fd\u6570\u5c06xml\u6570\u636e\u89e3\u6790\u5230\u7ed3\u6784\u4f53\u4e2d\u3002<\/li>\n<li>\u904d\u5386\u7ed3\u6784\u4f53\u4e2d\u7684\u5b57\u6bb5\u6765\u63d0\u53d6\u6240\u9700\u7684\u6570\u636e\u3002<\/li>\n<\/ol>\n<pre>package main\n\nimport (\n    \"encoding\/xml\"\n    \"fmt\"\n)\n\ntype Workbook struct {\n    XMLName                xml.Name               `xml:\"Workbook\"`\n    Text                   string                 `xml:\",chardata\"`\n    Xmlns                  string                 `xml:\"xmlns,attr\"`\n    O                      string                 `xml:\"o,attr\"`\n    X                      string                 `xml:\"x,attr\"`\n    Ss                     string                 `xml:\"ss,attr\"`\n    Html                   string                 `xml:\"html,attr\"`\n    DocumentProperties     DocumentProperties     `xml:\"DocumentProperties\"`\n    OfficeDocumentSettings OfficeDocumentSettings `xml:\"OfficeDocumentSettings\"`\n    ExcelWorkbook          ExcelWorkbook          `xml:\"ExcelWorkbook\"`\n    Styles                 Styles                 `xml:\"Styles\"`\n    Worksheet              Worksheet              `xml:\"Worksheet\"`\n}\n\ntype DocumentProperties struct {\n    Text   string `xml:\",chardata\"`\n    Xmlns  string `xml:\"xmlns,attr\"`\n    Author struct {\n        Text string `xml:\",chardata\"`\n    } `xml:\"Author\"`\n    LastAuthor struct {\n        Text string `xml:\",chardata\"`\n    } `xml:\"LastAuthor\"`\n    Created struct {\n        Text string `xml:\",chardata\"`\n    } `xml:\"Created\"`\n    LastSaved struct {\n        Text string `xml:\",chardata\"`\n    } `xml:\"LastSaved\"`\n    Version struct {\n        Text string `xml:\",chardata\"`\n    } `xml:\"Version\"`\n}\n\ntype OfficeDocumentSettings struct {\n    Text     string `xml:\",chardata\"`\n    Xmlns    string `xml:\"xmlns,attr\"`\n    AllowPNG struct {\n        Text string `xml:\",chardata\"`\n    } `xml:\"AllowPNG\"`\n}\n\ntype ExcelWorkbook struct {\n    Text         string `xml:\",chardata\"`\n    Xmlns        string `xml:\"xmlns,attr\"`\n    WindowHeight struct {\n        Text string `xml:\",chardata\"`\n    } `xml:\"WindowHeight\"`\n    WindowWidth struct {\n        Text string `xml:\",chardata\"`\n    } `xml:\"WindowWidth\"`\n    WindowTopX struct {\n        Text string `xml:\",chardata\"`\n    } `xml:\"WindowTopX\"`\n    WindowTopY struct {\n        Text string `xml:\",chardata\"`\n    } `xml:\"WindowTopY\"`\n    ProtectStructure struct {\n        Text string `xml:\",chardata\"`\n    } `xml:\"ProtectStructure\"`\n    ProtectWindows struct {\n        Text string `xml:\",chardata\"`\n    } `xml:\"ProtectWindows\"`\n}\n\ntype Styles struct {\n    Text  string `xml:\",chardata\"`\n    Style []struct {\n        Text      string `xml:\",chardata\"`\n        ID        string `xml:\"ID,attr\"`\n        Name      string `xml:\"Name,attr\"`\n        Parent    string `xml:\"Parent,attr\"`\n        Alignment struct {\n            Text       string `xml:\",chardata\"`\n            Vertical   string `xml:\"Vertical,attr\"`\n            Horizontal string `xml:\"Horizontal,attr\"`\n        } `xml:\"Alignment\"`\n        Borders struct {\n            Text string `xml:\",chardata\"`\n        } `xml:\"Borders\"`\n        Font struct {\n            Text     string `xml:\",chardata\"`\n            FontName string `xml:\"FontName,attr\"`\n            CharSet  string `xml:\"CharSet,attr\"`\n            Size     string `xml:\"Size,attr\"`\n            Color    string `xml:\"Color,attr\"`\n        } `xml:\"Font\"`\n        Interior struct {\n            Text    string `xml:\",chardata\"`\n            Color   string `xml:\"Color,attr\"`\n            Pattern string `xml:\"Pattern,attr\"`\n        } `xml:\"Interior\"`\n        NumberFormat struct {\n            Text   string `xml:\",chardata\"`\n            Format string `xml:\"Format,attr\"`\n        } `xml:\"NumberFormat\"`\n        Protection struct {\n            Text      string `xml:\",chardata\"`\n            Protected string `xml:\"Protected,attr\"`\n        } `xml:\"Protection\"`\n    } `xml:\"Style\"`\n}\n\ntype Worksheet struct {\n    Text  string `xml:\",chardata\"`\n    Name  string `xml:\"Name,attr\"`\n    Table struct {\n        Text                string `xml:\",chardata\"`\n        ExpandedColumnCount string `xml:\"ExpandedColumnCount,attr\"`\n        ExpandedRowCount    string `xml:\"ExpandedRowCount,attr\"`\n        FullColumns         string `xml:\"FullColumns,attr\"`\n        FullRows            string `xml:\"FullRows,attr\"`\n        DefaultColumnWidth  string `xml:\"DefaultColumnWidth,attr\"`\n        DefaultRowHeight    string `xml:\"DefaultRowHeight,attr\"`\n        Column              []struct {\n            Text    string `xml:\",chardata\"`\n            StyleID string `xml:\"StyleID,attr\"`\n            Width   string `xml:\"Width,attr\"`\n            Span    string `xml:\"Span,attr\"`\n            Index   string `xml:\"Index,attr\"`\n        } `xml:\"Column\"`\n        Row []struct {\n            Text          string `xml:\",chardata\"`\n            AutoFitHeight string `xml:\"AutoFitHeight,attr\"`\n            StyleID       string `xml:\"StyleID,attr\"`\n            Cell          []struct {\n                Text    string `xml:\",chardata\"`\n                StyleID string `xml:\"StyleID,attr\"`\n                Data    struct {\n                    Text string `xml:\",chardata\"`\n                    Type string `xml:\"Type,attr\"`\n                } `xml:\"Data\"`\n            } `xml:\"Cell\"`\n        } `xml:\"Row\"`\n    } `xml:\"Table\"`\n    WorksheetOptions struct {\n        Text      string `xml:\",chardata\"`\n        Xmlns     string `xml:\"xmlns,attr\"`\n        PageSetup struct {\n            Text   string `xml:\",chardata\"`\n            Header struct {\n                Text   string `xml:\",chardata\"`\n                Margin string `xml:\"Margin,attr\"`\n            } `xml:\"Header\"`\n            Footer struct {\n                Text   string `xml:\",chardata\"`\n                Margin string `xml:\"Margin,attr\"`\n            } `xml:\"Footer\"`\n            PageMargins struct {\n                Text   string `xml:\",chardata\"`\n                Bottom string `xml:\"Bottom,attr\"`\n                Left   string `xml:\"Left,attr\"`\n                Right  string `xml:\"Right,attr\"`\n                Top    string `xml:\"Top,attr\"`\n            } `xml:\"PageMargins\"`\n        } `xml:\"PageSetup\"`\n        Unsynced struct {\n            Text string `xml:\",chardata\"`\n        } `xml:\"Unsynced\"`\n        Print struct {\n            Text             string `xml:\",chardata\"`\n            ValidPrinterInfo struct {\n                Text string `xml:\",chardata\"`\n            } `xml:\"ValidPrinterInfo\"`\n            PaperSizeIndex struct {\n                Text string `xml:\",chardata\"`\n            } `xml:\"PaperSizeIndex\"`\n            HorizontalResolution struct {\n                Text string `xml:\",chardata\"`\n            } `xml:\"HorizontalResolution\"`\n            VerticalResolution struct {\n                Text string `xml:\",chardata\"`\n            } `xml:\"VerticalResolution\"`\n        } `xml:\"Print\"`\n        Selected struct {\n            Text string `xml:\",chardata\"`\n        } `xml:\"Selected\"`\n        Panes struct {\n            Text string `xml:\",chardata\"`\n            Pane struct {\n                Text   string `xml:\",chardata\"`\n                Number struct {\n                    Text string `xml:\",chardata\"`\n                } `xml:\"Number\"`\n                ActiveRow struct {\n                    Text string `xml:\",chardata\"`\n                } `xml:\"ActiveRow\"`\n                ActiveCol struct {\n                    Text string `xml:\",chardata\"`\n                } `xml:\"ActiveCol\"`\n            } `xml:\"Pane\"`\n        } `xml:\"Panes\"`\n        ProtectObjects struct {\n            Text string `xml:\",chardata\"`\n        } `xml:\"ProtectObjects\"`\n        ProtectScenarios struct {\n            Text string `xml:\",chardata\"`\n        } `xml:\"ProtectScenarios\"`\n    } `xml:\"WorksheetOptions\"`\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    fmt.Println(book.Worksheet.Table.Row)\n}\n\nvar xmldata = `\n &lt;?xml version=\"1.0\"?&gt;\n&lt;?mso-application progid=\"Excel.Sheet\"?&gt;\n&lt;Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\n xmlns:o=\"urn:schemas-microsoft-com:office:office\"<\/pre>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8eGOLANG\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   IntelliJ IDEA for Mac\u4e2d\uff0c\u5982\u4f55\u627e\u5230\u548c\u914d\u7f6eMaven\u5b89\u88c5\u8def\u5f84\u53ca\u76f8\u5173\u6587\u4ef6\uff1f\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u5982\u4f55\u5b9e\u73b0\u7535\u8111\u624b\u673a\u6587\u4ef6\u5171\u4eab\uff0c\u8ba9\u4f60\u7684\u529e\u516c\u751f\u6d3b\u66f4\u4fbf\u5229\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587 \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-206272","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206272","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=206272"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206272\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}