导出原理
docx是一个压缩包,我们新建一个docx文档,添加一些内容,后缀名改为.zip进行解压
其中word下面结构如下
其中document.xml主要就是文档内容。
打开document.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 wp14">
<w:body>
<w:p w:rsidR="005E21F0" w:rsidRDefault="00EC00A2">
<w:r>
<w:t>Aaa</w:t>
</w:r>
<w:bookmarkStart w:id="0" w:name="_GoBack"/>
<w:bookmarkEnd w:id="0"/>
</w:p>
<w:sectPr w:rsidR="005E21F0">
<w:pgSz w:w="11906" w:h="16838"/>
<w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="851" w:footer="992"
w:gutter="0"/>
<w:cols w:space="425"/>
<w:docGrid w:type="lines" w:linePitch="312"/>
</w:sectPr>
</w:body>
</w:document>
可以看到刚才输入的内容Aaa
所以我们只需用freemarker生成一个叫document.xml的文档替换我们设计好的模板下的同名文件重新打包就可以导出指定格式的docx文档了。
需要注意打包时,选择的时解压出来新建文档 文件夹下所有内容,而不是外面的文件夹
下面从头开始演示如何生成
新建一个docx文档,并设计好需要的格式
修改后缀为zip并解压
把word下面的document.xml剪切出来
剩下的重新打成zip包
把zip包和document.xml重新命名为crossExport.zip 和crossExport.ftl
修改crossExport.ftl
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:r="http://purl.oclc.org/ooxml/officeDocument/relationships"
xmlns:m="http://purl.oclc.org/ooxml/officeDocument/math" xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
xmlns:wp="http://purl.oclc.org/ooxml/drawingml/wordprocessingDrawing"
xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://purl.oclc.org/ooxml/wordprocessingml/main"
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" mc:Ignorable="w14 w15 wne wp14"
w:conformance="strict">
<w:body>
<w:p w:rsidR="00E35097" w:rsidRPr="00EF0F10" w:rsidRDefault="00EF0F10">
<w:pPr>
<w:adjustRightInd w:val="0"/>
<w:snapToGrid w:val="0"/>
<w:ind w:firstLineChars="0" w:firstLine="0pt"/>
<w:jc w:val="center"/>
<w:rPr>
<w:rFonts w:ascii="仿宋" w:eastAsia="仿宋" w:hAnsi="仿宋"/>
<w:b/>
<w:bCs/>
<w:sz w:val="72"/>
<w:szCs w:val="48"/>
</w:rPr>
</w:pPr>
<w:r w:rsidRPr="00EF0F10">
<w:rPr>
<w:rFonts w:ascii="仿宋" w:eastAsia="仿宋" w:hAnsi="仿宋" w:hint="eastAsia"/>
<w:b/>
<w:bCs/>
<w:sz w:val="56"/>
<w:szCs w:val="48"/>
</w:rPr>
<w:t>${projectName}交叉跨越校验报告</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00E35097" w:rsidRDefault="005A31A9">
<w:pPr>
<w:adjustRightInd w:val="0"/>
<w:snapToGrid w:val="0"/>
<w:ind w:firstLine="48.20pt"/>
<w:rPr>
<w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
<w:b/>
<w:bCs/>
<w:sz w:val="48"/>
<w:szCs w:val="48"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312" w:hint="eastAsia"/>
<w:b/>
<w:bCs/>
<w:sz w:val="48"/>
<w:szCs w:val="48"/>
</w:rPr>
<w:tab/>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312" w:hint="eastAsia"/>
<w:b/>
<w:bCs/>
<w:sz w:val="48"/>
<w:szCs w:val="48"/>
</w:rPr>
<w:tab/>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312" w:hint="eastAsia"/>
<w:b/>
<w:bCs/>
<w:sz w:val="48"/>
<w:szCs w:val="48"/>
</w:rPr>
<w:tab/>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312" w:hint="eastAsia"/>
<w:b/>
<w:bCs/>
<w:sz w:val="48"/>
<w:szCs w:val="48"/>
</w:rPr>
<w:tab/>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312" w:hint="eastAsia"/>
<w:b/>
<w:bCs/>
<w:sz w:val="48"/>
<w:szCs w:val="48"/>
</w:rPr>
<w:tab/>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312" w:hint="eastAsia"/>
<w:b/>
<w:bCs/>
<w:sz w:val="48"/>
<w:szCs w:val="48"/>
</w:rPr>
<w:tab/>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312" w:hint="eastAsia"/>
<w:b/>
<w:bCs/>
<w:sz w:val="48"/>
<w:szCs w:val="48"/>
</w:rPr>
<w:tab/>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312" w:hint="eastAsia"/>
<w:b/>
<w:bCs/>
<w:sz w:val="48"/>
<w:szCs w:val="48"/>
</w:rPr>
<w:tab/>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312" w:hint="eastAsia"/>
<w:b/>
<w:bCs/>
<w:sz w:val="48"/>
<w:szCs w:val="48"/>
</w:rPr>
<w:tab/>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312" w:hint="eastAsia"/>
<w:b/>
<w:bCs/>
<w:sz w:val="48"/>
<w:szCs w:val="48"/>
</w:rPr>
<w:tab/>
</w:r>
</w:p>
<w:p w:rsidR="00E35097" w:rsidRDefault="00E35097">
<w:pPr>
<w:adjustRightInd w:val="0"/>
<w:snapToGrid w:val="0"/>
<w:ind w:firstLine="36pt"/>
<w:jc w:val="center"/>
<w:rPr>
<w:rFonts w:eastAsia="仿宋_GB2312"/>
<w:spacing w:val="20"/>
<w:sz w:val="32"/>
</w:rPr>
</w:pPr>
</w:p>
<w:p w:rsidR="00E35097" w:rsidRDefault="00E35097">
<w:pPr>
<w:adjustRightInd w:val="0"/>
<w:snapToGrid w:val="0"/>
<w:ind w:firstLine="36pt"/>
<w:jc w:val="center"/>
<w:rPr>
<w:rFonts w:eastAsia="仿宋_GB2312"/>
<w:spacing w:val="20"/>
<w:sz w:val="32"/>
</w:rPr>
</w:pPr>
</w:p>
<w:p w:rsidR="00E35097" w:rsidRDefault="00E35097">
<w:pPr>
<w:adjustRightInd w:val="0"/>
<w:snapToGrid w:val="0"/>
<w:ind w:firstLine="36pt"/>
<w:jc w:val="center"/>
<w:rPr>
<w:rFonts w:eastAsia="仿宋_GB2312"/>
<w:spacing w:val="20"/>
<w:sz w:val="32"/>
</w:rPr>
</w:pPr>
</w:p>
<w:p w:rsidR="00E35097" w:rsidRDefault="00E35097">
<w:pPr>
<w:adjustRightInd w:val="0"/>
<w:snapToGrid w:val="0"/>
<w:ind w:firstLine="36pt"/>
<w:jc w:val="center"/>
<w:rPr>
<w:rFonts w:eastAsia="仿宋_GB2312"/>
<w:spacing w:val="20"/>
<w:sz w:val="32"/>
</w:rPr>
</w:pPr>
</w:p>
<w:p w:rsidR="00E35097" w:rsidRDefault="00E35097">
<w:pPr>
<w:adjustRightInd w:val="0"/>
<w:snapToGrid w:val="0"/>
<w:ind w:firstLine="36pt"/>
<w:jc w:val="center"/>
<w:rPr>
<w:rFonts w:eastAsia="仿宋_GB2312"/>
<w:spacing w:val="20"/>
<w:sz w:val="32"/>
</w:rPr>
</w:pPr>
</w:p>
<w:p w:rsidR="00E35097" w:rsidRDefault="00E35097" w:rsidP="005F6F99">
<w:pPr>
<w:spacing w:line="26pt" w:lineRule="exact"/>
<w:ind w:firstLineChars="0" w:firstLine="0pt"/>
<w:rPr>
<w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312" w:hint="eastAsia"/>
<w:b/>
<w:sz w:val="32"/>
<w:szCs w:val="32"/>
</w:rPr>
</w:pPr>
</w:p>
<w:p w:rsidR="00E35097" w:rsidRDefault="007071AD">
<w:pPr>
<w:adjustRightInd w:val="0"/>
<w:snapToGrid w:val="0"/>
<w:ind w:firstLineChars="0"/>
<w:jc w:val="center"/>
<w:rPr>
<w:rFonts w:ascii="仿宋_GB2312" w:eastAsia<