【发布时间】:2017-01-05 12:52:14
【问题描述】:
我一直在阅读 Wouter van Vugt 的“Open XML。标记解释”。
“Wordprocessing ML”一章包含相当简单的手动创建简单 docx 文件的演练,方法是创建几个 xml 部分文件,将其压缩并重命名为 *.docx。
我已经严格按照说明进行操作,但是当我尝试使用 Open XML SDK Productivity Tool 打开最终的 *.zip 文件时出现错误:“无法打开文件:不支持指定的文件类型”。
我尝试使用 MS Word 创建一个 docx 文件,将其重命名为 *.zip 并使用生产力工具打开它。有效。这个文件中的部分比手动创建的要多得多,但描述性部分实际上是相同的。
我做错了什么?
P.S.:是的,我知道 OOXML 应该是通过一些与 .NET 兼容的代码创建的,而不是通过手动创建 XML 内容。但我试图理解它的结构,但我不明白。
创建文件的内容:
[内容类型].xml:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
<Default Extension="xml" ContentType="application/xml" />
<Override PartName="/Document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.mainxml" />
</Types>
文档.xml:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:r>
<w:t>Hello World!</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
.rels:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="Document.xml" />
</Relationships>
【问题讨论】:
标签: openxml openxml-sdk