序言
在开发过程中经常遇到office文件相关的问题,比如将数据导出成Excel、自动生成报表、自动生成填充合同模板、转pdf等。UOffice是一个为解决这类Office文件问题的项目,里面记录了到目前为止,笔者遇到的相关问题的解决方案。笔者希望UOffice能称为一个完善的集合,但是靠一个人很难做到完善,所以这个项目后续会公开到github上,希望能为大家提供便利,也希望大家共同完善功能,使之更加健壮。
(.xlsx、.docx、.pptx)文件解析
.xlsx、.docx、.pptx是ooxml格式的office文件,简单了来说就是(压缩+xml)的格式。也就说你可以用压缩工具(比如7zip)将一个xlsx(或docx、pptx)文件解压。以xlsx为例,其他文件格式类似。
下面详细介绍下主要的几个部分的作用。
xl/sharedStrings.xml
此文件主要保本excel中各个单元格文本的内容。
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="2" uniqueCount="2">
<si>
<t>我是</t>
<phoneticPr fontId="1" type="noConversion"/>
</si>
<si>
<t>Uoffice</t>
<phoneticPr fontId="1" type="noConversion"/>
</si>
</sst>
其中内容是去重的,相同的内容只能存一份。count代表总数,uniqueCount是去重后的数量。
xl/styles.xml
此文件主要存单元格的格式信息
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" mc:Ignorable="x14ac">
<fonts count="2" x14ac:knownFonts="1">
<font>
<sz val="11"/>
<color theme="1"/>
<name val="宋体"/>
<charset val="134"/>
<scheme val="minor"/>
</font>
<font>
<sz val="9"/>
<name val="宋体"/>
<charset val="134"/>
<scheme val="minor"</