Office Open XML文件规范学习



近期在做一些文档追踪方案的学习和测试,除了纯文本的txt/csv文本格式之外,用的最多的就是Office文档了,在新的Office套件里面早就默认使用了 docx/xlsx/pptx 后缀,而非之前的 doc/xls/ppt 后缀,新后缀对应的文件用的就是Office Open XML文件格式。为了更好的理解文档追踪方案的优势和局限,所以学习了解一下相关文件格式规范。并这里简单记录一下在学习了解Office Open XML文件格式过程中的内容,方便后面有需要的时候再参考和回顾。


  1. Office Open XML 是什么?

Office Open XML(缩写:Open XML、OpenXML或OOXML),为由Microsoft开发的一种以XML为基础并以ZIP格式压缩的电子文件规范,支持文件、表格、幻灯片等文件格式。

OOXML在2006年12月成为了ECMA规范的一部分,编号为ECMA-376;并于2008年4月通过国际标准化组织的表决,在两个月后公布为ISO/IEC 29500国际标准。微软推出这个格式,很多人认为是出于商业考量。许多专家指出,该标准并不是个完整的标准,采用了许多微软的独有规格,使用上困难重重。

从Microsoft Office 2007开始,Office Open XML文件格式已经成为Microsoft Office默认的文件格式。Microsoft Office 2010支持对ECMA-376标准文档的读操作,ISO/IEC 29500 Transitional的读/写,ISO/IEC 29500 Strict的读取。Microsoft Office 2013同时支持ISO/IEC 29500 Strict的读写操作。

Starting with the 2007 Microsoft Office system, Microsoft Office uses the XML-based file formats, such as .docx, .xlsx, and .pptx. These formats and file name extensions apply to Microsoft Word, Microsoft Excel, and Microsoft PowerPoint.

  1. docx/xlsx/pptx 文件的结构
[Content_Types].xml #这个文件包含所有内容类型的列表。每个部件及其类型必须列在[Content_Types].xml中
_rels #用于配置定义各part间的关系,在part内部也会有各_rels子目录及关系文件
docProps #存放属性相关内容
	app.xml #扩展属性
	core.xml #核心属性
	custom.xml #自定义属性(默认可能没有这个文件,需要添加自定义属性之后才会有该文件)

word #docx特有目录
xl #xlsx特有目录
ppt #pptx特有目录


  1. 以 docx 文件为例介绍内部文件的功能和作用
  • Content Types

根目录下的 [Content_Types].xml 文件

Every package must have a [Content_Types].xml, found at the root of the package. This file contains a list of all of the content types of the parts in the package. Every part and its type must be listed in [Content_Types].xml.

It’s important to keep this in mind when adding new parts to the package.

  • Relationships

根目录下的 _rels 目录(及各part内部目录中的 _rels 子目录)

Every package contains a relationships part that defines the relationships between the other parts and to resources outside of the package. This separates the relationships from content and makes it easy to change relationships without changing the sources that reference targets.

In addition to the relationships part for the package, each part that is the source of one or more relationships will have its own relationships part. Each such relationship part is found within a _rels sub-folder of the part and is named by appending ‘.rels’ to the name of the part. Typically the main content part (document.xml) has its own relationships part(document.xml.rels). It will contain relationships to the other parts of the content, such as styles.xml, themes,xml, and footer.xml, as well as the URIs for external links.

  • Parts Shared by Other OOXML Documents

根目录下的 docProps 目录(还有一些其他parts)

Embedded packageContains a complete package, either internal or external to the referencing package. For example, a WordprocessingML document might contain a spreadsheet or presentation document.
Image图片。Documents often contain images. An image can be stored in a package as a zip item. The item must be identified by an image part relationship and the appropriate content type.
  • Parts Specific to WordprocessingML Documents

根目录下的 word 目录(xlsx是 xl 目录,pptx是 ppt 目录)


Office Open XML


Open XML Formats and file name extensions

Anatomy of a WordProcessingML File

ECMA-376 -> Office Open XML file formats (5th edition, December 2021)

微软在Office Open XML夹了多少私货?



声明: 除非注明,ixyzero.com文章均为原创,转载请以链接形式标明本文地址,谢谢!

《Office Open XML文件规范学习》上的5个想法

  1. 使用POI在Excel中添加外部图片
    Load remote image inside excel sheet

    Put hyperlink into image in excel (Apache POI)
    When looking at how Excel stores this it seems to be stored differently for Images in the xl\drawings\_rels\drawing1.xml.rels and xl\drawings\drawing1.xml part of the XLSX file.

  2. DrawingML Overview
    DrawingML is the language for defining graphical objects such as pictures, shapes, charts, and diagrams within ooxml documents. It also specifies package-wide appearance characteristics, i.e., the package’s theme. DrawingML is not a standalone markup language; it supports and appears within wordprocessingML, spreadsheetML, and presentationML documents. DrawingML is distinct from SVG and VML. SVG (scaleable vector graphics) is a graphics file format for two-dimensional graphics in XML. It is used mostly on the web and in desktop publishing. VML is a competing language for vector graphic files. It is now largely deprecated in favor of SVG. According to the ECMA OOXML specification, “The DrawingML format is a newer and richer format created with the goal of eventually replacing any uses of VML in the Office Open XML formats. VML is a transitional format; it is included in Office Open XML for legacy reasons only.” VML is still used extensively within Microsoft Word for certain graphic comnponents, in particular for things as shapes and text boxes.

    DrawingML 是在ooxml文档中定义图形对象(如图片、形状、图表和图解)的语言。它还指定了包范围的外观特征,即包的主题。DrawingML不是一种独立的标记语言;它支持并出现在wordprocessingML、spreadsheetML和presentationML文档中。DrawingML不同于SVG和VML。SVG(可伸缩矢量图形)是用于XML中的二维图形的图形文件格式,它主要用于网络和桌面出版。VML是一种用于矢量图形文件的竞争性语言,现在它在很大程度上已被SVG所弃用。根据ECMA OOXML规范,“DrawingML格式是一种更新、更丰富的格式,其目标是最终取代Office Open XML格式中VML的任何用途。VML是一种过渡格式;它被包含在Office Open XML中只是因为遗留问题。”在Microsoft Word中,VML仍然广泛用于某些图形组件,特别是形状和文本框。