2. 续 日
GitHub
§ github.com/xuri
Blog
2
⽬前就职于阿⾥巴巴,担任⾼级开发⼯程师,前百度 Go 语⾔编程委员会成员。开源软件
爱好者、W3C Member,专注于 Go 语⾔实践、中间件研发与⼤规模数据处理。
Currently working at Alibaba Group, as a software engineer, previous at Baidu Inc., as a
member of the Baidu Go language programming committee. Open-source software
enthusiasts and W3C open-source members. Focus on the Go language practice, middleware
development, and large-scale data processing.
§ xuri.me
4. 文档格式国际标准
Standard for Document File Formats
标准特点
§ Apple
§ BP
§ Essilor
§ Intel
§ Microsoft
§ Statoil
§ The British Library
§ Toshiba
§ United States Library of Congress
§ …
4
TC (Technical Committee) 45 代表
§ 互操作性
§ 国际化
§ 对开发⼈员采⽤的障碍较低
§ ⾼保真迁移
§ 与业务数据集成
§ 创新空间
ECMA-376, ISO/IEC 29500
10. 典型关系图
Typical Workbook Scenario
10
A typical workbook will not be a blank, minimum
workbook. A typical workbook might contain numbers,
text, charts, tables, and pivot tables. Each of these
additional parts is contained within the .zip package of
the spreadsheet document.
右图展示了⼀个包含了数字、⽂本、图表、表
格和数据透视表的典型电⼦表格⽂档 ZIP 包内
数据分布关系。
12. 12
Excelize 是 Go 语⾔编写的⽤于操作 Office Excel ⽂档类库,基于 ECMA-376, ISO/IEC
29500 国际电⼦表格⽂档格式标准。可以使⽤它来读取、写⼊由 Microsoft Excel™
2007 及以上版本创建的 XLSX ⽂档,可以应⽤于各类报表系统和边缘计算系统中,作为
2018 开源中国最有价值开源项⽬,⽬前已成为 Go 语⾔最受欢迎的 Excel ⽂档基础库。
Excelize is a library written in pure Go and providing a set of functions that allow you to write to and read from
XLSX files. Support reads and writes XLSX file generated by Microsoft Excel™ 2007 and later. Support save file
without losing original charts of XLSX. This library needs Go version 1.10 or later.
Go 语言实现
Implementation in Go Language
22. 22
Go 语言处理多命名空间 XML 时的问题
The Issue About Handle Multi XML Namespace Prefixes in Go Language
使⽤如左图所示的结构体对 XML 先进⾏反序列化 (Unmarshal)
再进⾏序列化(Marshal),所得结果与原 XML 不⼀致。
相关 Issue:https://github.com/golang/go/issues/13400
23. 23
Go 语言处理多命名空间 XML
Handle Multi XML Namespace Prefixes in Go Language
定义两套结构体分别进⾏反序列化和序列化操作。序列
化时,在结构体的 Tag 中,通过冒号连接命名空间和其
所属的属性或标签名,做为整体处理。
解决⽅案
24. 24
Sparkline (迷你图) 的 XML ⽚段
电子表格文档中的多命名空间 XML
Multi XML Namespace Prefixes in Spreadsheet Documents
在电⼦表格⽂档处理过程中涉及到⼤量
包含多命名空间的 XML 处理场景。
25. 25
Excelize 处理多命名空间 XML
Handle Multi XML Namespace Prefixes in the Excelize
解决⽅案
反序列化时:为保留原始命名空间信息,利⽤ innerxml Tag,
将 decodeWorksheetExt.Ext.Content 做为
decodeX14SparklineGroups 的 Wrapper
序列化时:先对 xlsxX14SparklineGroups 进⾏序列化,将序
列化结果做为 xlsxWorksheetExt.Content 的值,最后对
xlsxWorksheetExt 进⾏序列化。
27. 结语
Conclusion
国际电⼦表格⽂档格式标准
27
Go 语⾔实现
Excelize 发展规划
ECMA-376, ISO/IEC 29500
Excelize
支持图片、图表、数据透视表等复杂样式
• Formula calculation engine
• Remove rows and columns
• Conditional formatting support
• Encryption support
• Pivot Chart support
• Set multiline texts to cells support
• VBA Script support
• Complex chart style support
• Unit test assert equal with the result
• Object Linking and Embedding (OLE) format support
• Set Accounting number format currently
• Remove Data Validation support
• Diagrams (SmartArt Graphic)
• Streaming Read and Writing