freemarker導出docx文檔

導出原理

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="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
            </w:pPr>
            <w:r>
                <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:t>${year}年${month}月${day}日</w:t>
            </w:r>
        </w:p>
        <w:p w:rsidR="00E35097" w:rsidRDefault="006C13D7">
            <w:pPr>
                <w:adjustRightInd w:val="0"/>
                <w:snapToGrid w:val="0"/>
                <w:ind w:start="210pt" w:firstLineChars="0" w:firstLine="21pt"/>
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
            </w:pPr>
            <w:r>
                <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:t xml:space="preserve">  </w:t>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
        </w:p>
        <w:p w:rsidR="00EF0F10" w:rsidRDefault="006C13D7">
            <w:pPr>
                <w:adjustRightInd w:val="0"/>
                <w:snapToGrid w:val="0"/>
                <w:ind w:start="210pt" w:firstLineChars="0" w:firstLine="21pt"/>
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
            </w:pPr>
            <w:r>
                <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:t xml:space="preserve">  </w:t>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
        </w:p>
        <w:p w:rsidR="00EF0F10" w:rsidRDefault="006C13D7">
            <w:pPr>
                <w:adjustRightInd w:val="0"/>
                <w:snapToGrid w:val="0"/>
                <w:ind w:start="210pt" w:firstLineChars="0" w:firstLine="21pt"/>
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
            </w:pPr>
            <w:r>
                <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:t xml:space="preserve">  </w:t>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
            <w:r w:rsidR="005F6F99">
                <w:rPr>
                    <w:rFonts w:ascii="仿宋_GB2312" w:eastAsia="仿宋_GB2312"/>
                    <w:b/>
                    <w:sz w:val="32"/>
                    <w:szCs w:val="32"/>
                </w:rPr>
                <w:tab/>
            </w:r>
        </w:p>
        <w:p w:rsidR="00E35097" w:rsidRPr="005F6F99" w:rsidRDefault="00E35097" w:rsidP="005F6F99">
            <w:pPr>
                <w:adjustRightInd w:val="0"/>
                <w:snapToGrid w:val="0"/>
                <w:ind w:start="210pt" w:firstLineChars="0" w:firstLine="21pt"/>
                <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:sectPr w:rsidR="00E35097" w:rsidRPr="005F6F99" w:rsidSect="005F6F99">
                    <w:headerReference w:type="even" r:id="rId9"/>
                    <w:headerReference w:type="default" r:id="rId10"/>
                    <w:footerReference w:type="even" r:id="rId11"/>
                    <w:footerReference w:type="default" r:id="rId12"/>
                    <w:headerReference w:type="first" r:id="rId13"/>
                    <w:footerReference w:type="first" r:id="rId14"/>
                    <w:pgSz w:w="842pt" w:h="595.35pt" w:orient="landscape"/>
                    <w:pgMar w:top="65.20pt" w:right="72pt" w:bottom="62.35pt" w:left="72pt" w:header="42.55pt"
                             w:footer="49.60pt" w:gutter="0pt"/>
                    <w:pgNumType w:fmt="upperRoman" w:start="1"/>
                    <w:cols w:space="21.25pt"/>
                    <w:formProt w:val="0"/>
                    <w:titlePg/>
                    <w:docGrid w:linePitch="380"/>
                </w:sectPr>
            </w:pPr>
        </w:p>
        <w:p w:rsidR="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="005F6F99">
            <w:pPr>
                <w:pStyle w:val="2"/>
                <w:numPr>
                    <w:ilvl w:val="0"/>
                    <w:numId w:val="2"/>
                </w:numPr>
            </w:pPr>
            <w:r>
                <w:rPr>
                    <w:rFonts w:hint="eastAsia"/>
                </w:rPr>
                <w:lastRenderedPageBreak/>
                <w:t>交叉跨越校驗報告</w:t>
            </w:r>
        </w:p>
        <w:tbl>
            <w:tblPr>
                <w:tblW w:w="701.70pt" w:type="dxa"/>
                <w:jc w:val="center"/>
                <w:tblBorders>
                    <w:top w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:start w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:bottom w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:end w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:insideV w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                </w:tblBorders>
                <w:tblLayout w:type="fixed"/>
                <w:tblLook w:firstRow="0" w:lastRow="0" w:firstColumn="0" w:lastColumn="0" w:noHBand="0" w:noVBand="0"/>
            </w:tblPr>
            <w:tblGrid>
                <w:gridCol w:w="709"/>
                <w:gridCol w:w="1028"/>
                <w:gridCol w:w="956"/>
                <w:gridCol w:w="843"/>
                <w:gridCol w:w="1001"/>
                <w:gridCol w:w="1128"/>
                <w:gridCol w:w="2127"/>
                <w:gridCol w:w="2551"/>
                <w:gridCol w:w="2273"/>
                <w:gridCol w:w="1418"/>
            </w:tblGrid>
            <w:tr w:rsidR="009E62D0" w:rsidRPr="00A46150" w:rsidTr="009E62D0">
                <w:trPr>
                    <w:jc w:val="center"/>
                </w:trPr>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:w="35.45pt" w:type="dxa"/>
                        <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                        <w:vAlign w:val="center"/>
                    </w:tcPr>
                    <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                        <w:pPr>
                            <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                            <w:jc w:val="center"/>
                        </w:pPr>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>序號</w:t>
                        </w:r>
                    </w:p>
                </w:tc>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:w="51.40pt" w:type="dxa"/>
                        <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                        <w:vAlign w:val="center"/>
                    </w:tcPr>
                    <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                        <w:pPr>
                            <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                            <w:jc w:val="center"/>
                        </w:pPr>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>校驗工況</w:t>
                        </w:r>
                    </w:p>
                </w:tc>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:w="47.80pt" w:type="dxa"/>
                        <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                        <w:vAlign w:val="center"/>
                    </w:tcPr>
                    <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                        <w:pPr>
                            <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                            <w:jc w:val="center"/>
                        </w:pPr>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>杆塔編號</w:t>
                        </w:r>
                    </w:p>
                </w:tc>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:w="42.15pt" w:type="dxa"/>
                        <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                        <w:vAlign w:val="center"/>
                    </w:tcPr>
                    <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                        <w:pPr>
                            <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                            <w:jc w:val="center"/>
                        </w:pPr>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>迴路</w:t>
                        </w:r>
                    </w:p>
                </w:tc>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:w="50.05pt" w:type="dxa"/>
                        <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                        <w:vAlign w:val="center"/>
                    </w:tcPr>
                    <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                        <w:pPr>
                            <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                            <w:jc w:val="center"/>
                        </w:pPr>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>相序</w:t>
                        </w:r>
                    </w:p>
                </w:tc>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:w="56.40pt" w:type="dxa"/>
                        <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                        <w:vAlign w:val="center"/>
                    </w:tcPr>
                    <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                        <w:pPr>
                            <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                            <w:jc w:val="center"/>
                        </w:pPr>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>地物名稱</w:t>
                        </w:r>
                    </w:p>
                </w:tc>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:w="106.35pt" w:type="dxa"/>
                        <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                        <w:vAlign w:val="center"/>
                    </w:tcPr>
                    <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                        <w:pPr>
                            <w:ind w:firstLineChars="150" w:firstLine="18pt"/>
                            <w:jc w:val="center"/>
                        </w:pPr>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>垂直</w:t>
                        </w:r>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>(m)</w:t>
                        </w:r>
                    </w:p>
                    <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                        <w:pPr>
                            <w:ind w:firstLineChars="150" w:firstLine="18pt"/>
                            <w:jc w:val="center"/>
                        </w:pPr>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>測量值</w:t>
                        </w:r>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>/</w:t>
                        </w:r>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>規程值</w:t>
                        </w:r>
                    </w:p>
                </w:tc>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:w="127.55pt" w:type="dxa"/>
                        <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                        <w:vAlign w:val="center"/>
                    </w:tcPr>
                    <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                        <w:pPr>
                            <w:ind w:firstLineChars="150" w:firstLine="18pt"/>
                            <w:jc w:val="center"/>
                        </w:pPr>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>水平</w:t>
                        </w:r>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>(m)</w:t>
                        </w:r>
                    </w:p>
                    <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                        <w:pPr>
                            <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                            <w:jc w:val="center"/>
                        </w:pPr>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>測量值</w:t>
                        </w:r>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>/</w:t>
                        </w:r>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>規程值</w:t>
                        </w:r>
                    </w:p>
                </w:tc>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:w="113.65pt" w:type="dxa"/>
                        <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                        <w:vAlign w:val="center"/>
                    </w:tcPr>
                    <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                        <w:pPr>
                            <w:ind w:firstLineChars="150" w:firstLine="18pt"/>
                            <w:jc w:val="center"/>
                        </w:pPr>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>淨空</w:t>
                        </w:r>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>(m)</w:t>
                        </w:r>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>測量值</w:t>
                        </w:r>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>/</w:t>
                        </w:r>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>規程值</w:t>
                        </w:r>
                    </w:p>
                </w:tc>
                <w:tc>
                    <w:tcPr>
                        <w:tcW w:w="70.90pt" w:type="dxa"/>
                        <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                        <w:vAlign w:val="center"/>
                    </w:tcPr>
                    <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                        <w:pPr>
                            <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                            <w:jc w:val="center"/>
                        </w:pPr>
                        <w:r w:rsidRPr="005F6F99">
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                            </w:rPr>
                            <w:t>是否安全</w:t>
                        </w:r>
                    </w:p>
                </w:tc>
            </w:tr>
            <#list resultList as result>
                <w:tr w:rsidR="009E62D0" w:rsidRPr="00A46150" w:rsidTr="009E62D0">
                    <w:trPr>
                        <w:jc w:val="center"/>
                    </w:trPr>
                    <w:tc>
                        <w:tcPr>
                            <w:tcW w:w="35.45pt" w:type="dxa"/>
                            <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                            <w:vAlign w:val="center"/>
                        </w:tcPr>
                        <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                            <w:pPr>
                                <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                                <w:jc w:val="center"/>
                            </w:pPr>
                            <w:r w:rsidRPr="005F6F99">
                                <w:rPr>
                                    <w:rFonts w:hint="eastAsia"/>
                                </w:rPr>
                                <w:t>${result_index+1}</w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                    <w:tc>
                        <w:tcPr>
                            <w:tcW w:w="51.40pt" w:type="dxa"/>
                            <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                            <w:vAlign w:val="center"/>
                        </w:tcPr>
                        <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                            <w:pPr>
                                <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                                <w:jc w:val="center"/>
                            </w:pPr>
                            <w:r w:rsidRPr="005F6F99">
                                <w:rPr>
                                    <w:rFonts w:hint="eastAsia"/>
                                </w:rPr>
                                <w:t>${(result.gimWorkingName)!""}</w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                    <w:tc>
                        <w:tcPr>
                            <w:tcW w:w="47.80pt" w:type="dxa"/>
                            <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                            <w:vAlign w:val="center"/>
                        </w:tcPr>
                        <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                            <w:pPr>
                                <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                                <w:jc w:val="center"/>
                            </w:pPr>
                            <w:r w:rsidRPr="005F6F99">
                                <w:rPr>
                                    <w:rFonts w:hint="eastAsia"/>
                                </w:rPr>
                                <w:t>${(result.spanName)!""}</w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                    <w:tc>
                        <w:tcPr>
                            <w:tcW w:w="42.15pt" w:type="dxa"/>
                            <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                            <w:vAlign w:val="center"/>
                        </w:tcPr>
                        <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                            <w:pPr>
                                <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                                <w:jc w:val="center"/>
                            </w:pPr>
                            <w:r w:rsidRPr="005F6F99">
                                <w:rPr>
                                    <w:rFonts w:hint="eastAsia"/>
                                </w:rPr>
                                <w:t>${(result.loopName)!""}</w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                    <w:tc>
                        <w:tcPr>
                            <w:tcW w:w="50.05pt" w:type="dxa"/>
                            <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                            <w:vAlign w:val="center"/>
                        </w:tcPr>
                        <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                            <w:pPr>
                                <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                                <w:jc w:val="center"/>
                            </w:pPr>
                            <w:r w:rsidRPr="005F6F99">
                                <w:rPr>
                                    <w:rFonts w:hint="eastAsia"/>
                                </w:rPr>
                                <w:t>${(result.phaseName)!""}</w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                    <w:tc>
                        <w:tcPr>
                            <w:tcW w:w="56.40pt" w:type="dxa"/>
                            <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                            <w:vAlign w:val="center"/>
                        </w:tcPr>
                        <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                            <w:pPr>
                                <w:ind w:firstLineChars="150" w:firstLine="18pt"/>
                            </w:pPr>
                            <w:r w:rsidRPr="005F6F99">
                                <w:rPr>
                                    <w:rFonts w:hint="eastAsia"/>
                                </w:rPr>
                                <w:t>${(result.groundObjectName)!""}</w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                    <w:tc>
                        <w:tcPr>
                            <w:tcW w:w="106.35pt" w:type="dxa"/>
                            <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                            <w:vAlign w:val="center"/>
                        </w:tcPr>
                        <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                            <w:pPr>
                                <w:ind w:firstLineChars="150" w:firstLine="18pt"/>
                                <w:jc w:val="center"/>
                            </w:pPr>
                            <w:r w:rsidRPr="005F6F99">
                                <w:rPr>
                                    <w:rFonts w:hint="eastAsia"/>
                                </w:rPr>
                                <w:t>${(result.verticalDistanceStr)!""}</w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                    <w:tc>
                        <w:tcPr>
                            <w:tcW w:w="127.55pt" w:type="dxa"/>
                            <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                            <w:vAlign w:val="center"/>
                        </w:tcPr>
                        <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                            <w:pPr>
                                <w:ind w:firstLineChars="150" w:firstLine="18pt"/>
                                <w:jc w:val="center"/>
                            </w:pPr>
                            <w:r w:rsidRPr="005F6F99">
                                <w:rPr>
                                    <w:rFonts w:hint="eastAsia"/>
                                </w:rPr>
                                <w:t>${(result.horizontalDistanceStr)!""}</w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                    <w:tc>
                        <w:tcPr>
                            <w:tcW w:w="113.65pt" w:type="dxa"/>
                            <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                            <w:vAlign w:val="center"/>
                        </w:tcPr>
                        <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                            <w:pPr>
                                <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                                <w:jc w:val="center"/>
                            </w:pPr>
                            <w:r w:rsidRPr="005F6F99">
                                <w:rPr>
                                    <w:rFonts w:hint="eastAsia"/>
                                </w:rPr>
                                <w:t>${(result.clearanceStr)!""}</w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                    <w:tc>
                        <w:tcPr>
                            <w:tcW w:w="70.90pt" w:type="dxa"/>
                            <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                            <w:vAlign w:val="center"/>
                        </w:tcPr>
                        <w:p w:rsidR="005F6F99" w:rsidRPr="005F6F99" w:rsidRDefault="005F6F99" w:rsidP="009E62D0">
                            <w:pPr>
                                <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                                <w:jc w:val="center"/>
                            </w:pPr>
                            <w:r w:rsidRPr="005F6F99">
                                <w:rPr>
                                    <w:rFonts w:hint="eastAsia"/>
                                </w:rPr>
                                <w:t>${(result.isSecurity)!""}</w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                </w:tr>
            </#list>
        </w:tbl>
        <w:p w:rsidR="005A31A9" w:rsidRDefault="00173FF2" w:rsidP="006C13D7">
            <w:pPr>
                <w:pStyle w:val="a4"/>
                <w:ind w:firstLineChars="0" w:firstLine="0pt"/>
                <w:rPr>
                    <w:rFonts w:ascii="宋體" w:eastAsia="宋體" w:hAnsi="宋體"/>
                </w:rPr>
            </w:pPr>
            <w:r>
                <w:rPr>
                    <w:rFonts w:ascii="宋體" w:eastAsia="宋體" w:hAnsi="宋體" w:hint="eastAsia"/>
                </w:rPr>
                <w:t xml:space="preserve">   </w:t>
            </w:r>
        </w:p>
        <w:sectPr w:rsidR="005A31A9" w:rsidSect="005F6F99">
            <w:footerReference w:type="even" r:id="rId15"/>
            <w:pgSz w:w="841.90pt" w:h="595.30pt" w:orient="landscape"/>
            <w:pgMar w:top="79.40pt" w:right="72pt" w:bottom="79.40pt" w:left="72pt" w:header="28.35pt"
                     w:footer="42.55pt" w:gutter="0pt"/>
            <w:cols w:space="21.25pt"/>
            <w:docGrid w:linePitch="380"/>
        </w:sectPr>
    </w:body>
</w:document>

controller部分代碼如下

    @GetMapping("/exportCrossResult")
    public void exportCrossResult(HttpServletRequest request,HttpServletResponse response,String projectName,String key){
        Map<String, Object> map = new HashMap();
        map.put("docFileName",projectName+"交叉跨越校驗報告.docx");
        map.put("filetype","crossExport");//filetype ftl模板名
        Calendar calendar = Calendar.getInstance();
        map.put("year",calendar.get(Calendar.YEAR)+"");
        map.put("month",calendar.get(Calendar.MONTH)+1);
        map.put("day",calendar.get(Calendar.DATE));
        map.put("projectName",projectName);

        List<LineStrideAcrossCheckData> list = (List<LineStrideAcrossCheckData>) request.getSession().getAttribute(key);
        request.getSession().removeAttribute(key);

        map.put("resultList",list);
        //導出文檔
        Word07Generatorutil.except07Word(map,response);
    }

其中docFileName是導出文件的名稱

fileType是ftl文件的名稱

其他數據是ftl文件所需數據

生成的工具類

package com.bochao.util;

import com.bochao.common.util.UUIDUtil;
import freemarker.template.Configuration;
import freemarker.template.Template;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName Word07Generatorutil
 * @Description TODO
 * @Author yueyiming
 * @Date 2020/6/15 14:03
 * Version 1.0
 **/
@Component
public class Word07Generatorutil {
    /**
     * 資料臨時文件夾
     */

    private static String tempDirPath;

    @Value("${file.tempDirPath}")
    public void setTempDirPath(String tempDirPath) {
        Word07Generatorutil.tempDirPath = tempDirPath;
    }

    protected final static Logger logger = LoggerFactory.getLogger(WordGenerator.class);
    private static Configuration configuration;
    private static Map<String, Template> allTemplates;

    static {

        logger.info("Word07Generatorutil--------------------");
        configuration = new Configuration(Configuration.VERSION_2_3_23);
        configuration.setDefaultEncoding("utf-8");
        configuration.setClassForTemplateLoading(WordGenerator.class, "/docxFtl");
        allTemplates = new HashMap();
    }

    /**
     * 根據模板在臨時路徑生成  word/document.xml
     * 並把其他文件複製到臨時目錄下
     *
     * @param dataMap
     * @param type
     * @return
     */
    public static String createDocx(Map<?, ?> dataMap, String type) throws Exception {


        allTemplates.put(type, configuration.getTemplate(type + ".ftl"));


        String path = tempDirPath + File.separator + UUIDUtil.getPrimaryKeyUUID() + File.separator + "word";
        File pFile = new File(path);
        if (!pFile.exists()) {
            pFile.mkdirs();
        }
        File f = new File(path, "document.xml");
        Template t = allTemplates.get(type);

        if (!f.exists()) {
            f.createNewFile();
        }

        try (Writer w = new OutputStreamWriter(new FileOutputStream(f), "utf-8")) {
            t.process(dataMap, w);

        }

        File zipfile = null;
        try (InputStream in = Word07Generatorutil.class.getClassLoader().getResourceAsStream("docxTemp" + File.separator + type + ".zip")) {
            zipfile = new File(tempDirPath + File.separator + UUIDUtil.getPrimaryKeyUUID() + File.separator + type + ".zip");
            File pZipfile = new File(zipfile.getParent());
//        if(pZipfile.isDirectory()){
            pZipfile.mkdirs();
//        }

            if (!zipfile.exists()) {
                zipfile.createNewFile();
            }
            try (FileOutputStream fileOutputStream = new FileOutputStream(zipfile)) {
                IOUtils.copy(in, fileOutputStream);
            }

            BoChaoPackageUtil.unZip(zipfile.getAbsolutePath(), pFile.getParent());
        } finally {
            if (zipfile != null) {
                deleteFileOrDir(zipfile.getParent());
            }

        }

        return pFile.getParent();
    }

    /**
     * @Author: yueyiming
     * @Date: 2020/6/17 9:41
     * @param: [map, response]
     * @return: void
     * @Description: 導出07word
     **/
    public static void except07Word(Map<String, Object> map, HttpServletResponse response) {
        File file = null;
        String path = null;
        try {
            path = createDocx(map, map.get("filetype").toString());
            //打包
            String dpath = tempDirPath + File.separator + UUIDUtil.getPrimaryKeyUUID();
            File pFile = new File(dpath);
            if (!pFile.exists()) {
                pFile.mkdirs();
            }
            String docxFileName = map.get("docFileName").toString();
            file = new File(pFile, docxFileName);
            if (!file.exists()) {
                file.createNewFile();
            }
            BoChaoPackageUtil.pag(file.getAbsolutePath(), path);
        } catch (Exception e) {
            e.printStackTrace();
        }


        try (InputStream fin = new FileInputStream(file);
             ServletOutputStream out = response.getOutputStream()) {


            response.setCharacterEncoding("utf-8");
            response.setContentType("application/msword");
            String docFileName = map.get("docFileName").toString();
            response.addHeader("Content-Disposition", "attachment;filename=" + new String(docFileName.getBytes("gb2312"), "ISO8859-1"));

            byte[] buffer = new byte[512];
            //boolean var11 = true;
            int bytesToRead;
            while ((bytesToRead = fin.read(buffer)) != -1) {
                out.write(buffer, 0, bytesToRead);
            }


        } catch (Exception var16) {
            logger.error(var16.getMessage(), var16);
        } finally {
            deleteFileOrDir(file.getParent());
            deleteFileOrDir(path);
        }


    }

    /**
     * 刪除文件或文件夾
     *
     * @param path
     * @return
     */
    public static boolean deleteFileOrDir(String path) {
        File file = new File(path);
        if (!file.exists()) {
            throw new RuntimeException("刪除的path" + path + "不存在!");
        }
        //文件刪除
        if (file.isFile()) {
            file.delete();
            return true;
        }

        //文件夾刪除
        deleterDir(path);
        return true;
    }

    /**
     * 刪除文件夾
     *
     * @param path
     * @return
     */
    public static boolean deleterDir(String path) {
        File file = new File(path);
        if (file.isFile()) {
            return false;
        }
        //文件夾刪除
        for (File childFile : file.listFiles()) {
            if (childFile.isFile()) {
                childFile.delete();
            } else {
                //刪除文件夾
                deleterDir(childFile.getAbsolutePath());
            }
        }
        file.delete();

        return true;
    }


}

打包解壓的工具類

package com.bochao.util;

import java.io.*;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.zip.CRC32;
import java.util.zip.CheckedOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * @ClassName BoChaoPackageUtil
 * @Description 打包工具不壓縮
 * @Author yueyiming
 * @Date 2020/6/15 11:16
 * Version 1.0
 **/
public class BoChaoPackageUtil {


    /**
     * @param zipPath     壓縮後的文件路徑
     * @param srcPathName 要壓縮的文件路徑
     *                    參數srcPathName也可以定義成數組形式,需調用方把參數封裝到數組中傳過來即可
     * @Author: yueyiming
     * @Date: 2020/6/16 9:08
     * @return: void
     * @Description: 壓縮單個或多文件方法
     **/
    private static void compress(String zipPath, String[] srcPathName) {
        //壓縮後的文件對象
        File zipFile = new File(zipPath);
        //創建寫出流操作
        try (FileOutputStream fileOutputStream = new FileOutputStream(zipFile);
             CheckedOutputStream cos = new CheckedOutputStream(fileOutputStream, new CRC32()); ZipOutputStream out = new ZipOutputStream(cos)) {

            out.setLevel(9);
            for (String srcPath : srcPathName) {
                //創建需要壓縮的文件對象
                File file = new File(srcPath);
                if (!file.exists()) {
                    throw new RuntimeException(srcPath + "不存在!");
                }
//                (1) 如果在zip壓縮文件中不需要一級文件目錄,定義String basedir = "";
//                下面的compress方法中當判斷文件file是目錄後不需要加上basedir = basedir + file.getName() + File.separator;
//                (2) 如果只是想在壓縮後的zip文件裏包含一級文件目錄,不包含二級以下目錄,
//                直接在這定義String basedir = file.getName() + File.separator;
//                下面的compress方法中當判斷文件file是目錄後不需要加上basedir = basedir + file.getName() + File.separator;
//                (3) 如果想壓縮後的zip文件裏包含一級文件目錄,也包含二級以下目錄,即zip文件裏的目錄結構和原文件一樣
//                在此定義String basedir = "";
//                下面的compress方法中當判斷文件file是目錄後需要加上basedir = basedir + file.getName() + File.separator;
                //String basedir = file.getName() + File.separator;
                String basedir = "";

                compress(file, out, basedir);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * @Author: yueyiming
     * @Date: 2020/6/16 9:11
     * @param: [file, out, basedir]
     * @return: void
     * @Description:
     **/
    private static void compress(File file, ZipOutputStream out, String basedir) {
        /*
         * 判斷是目錄還是文件
         */
        if (file.isDirectory()) {
            basedir += file.getName() + File.separator;
            compressDirectory(file, out, basedir);
        } else {
            compressFile(file, out, basedir);
        }
    }

    /**
     * @Author: yueyiming
     * @Date: 2020/6/16 9:11
     * @param: [dir, out, basedir]
     * @return: void
     * @Description: 壓縮目錄
     **/
    private static void compressDirectory(File dir, ZipOutputStream out, String basedir) {
        if (!dir.exists()) {
            return;
        }
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; i++) {
            /* 遞歸 */
            compress(files[i], out, basedir);
        }
    }

    /**
     * 壓縮一個文件
     */
    private static void compressFile(File file, ZipOutputStream out, String basedir) {
        if (!file.exists()) {
            return;
        }
        try (BufferedInputStream bis = new BufferedInputStream(
                new FileInputStream(file))) {
            //創建Zip實體,並添加進壓縮包
            ZipEntry entry = new ZipEntry(basedir + file.getName());
            out.putNextEntry(entry);
            //讀取待壓縮的文件並寫進壓縮包裏
            int count;
            byte data[] = new byte[8192];
            while ((count = bis.read(data, 0, 8192)) != -1) {
                out.write(data, 0, count);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    /**
     * @Author: yueyiming
     * @Date: 2020/6/16 9:11
     * @param: [zipPath, srcPathName]
     * @return: void
     * @Description: 打包目錄下srcPathName的文件
     **/
    public static void pag(String zipPath, String srcPathName) {
        File file = new File(srcPathName);
        File[] files = file.listFiles();
        String[] strings = Arrays.stream(files).map(f -> f.getAbsolutePath()).toArray(String[]::new);
        compress(zipPath, strings);
    }

    /**
     * 解壓zip文件
     *
     * @param zipFileName     待解壓的zip文件路徑,例如:c:\\a.zip
     * @param outputDirectory 解壓目標文件夾,例如:c:\\a\
     */
    public static void unZip(String zipFileName, String outputDirectory)
            throws Exception {
        org.apache.tools.zip.ZipFile zipFile = new org.apache.tools.zip.ZipFile(zipFileName);
        try {
            Enumeration<?> e = zipFile.getEntries();
            org.apache.tools.zip.ZipEntry zipEntry = null;
            createDirectory(outputDirectory, "");
            while (e.hasMoreElements()) {
                zipEntry = (org.apache.tools.zip.ZipEntry) e.nextElement();
                if (zipEntry.isDirectory()) {
                    String name = zipEntry.getName();
                    name = name.substring(0, name.length() - 1);
                    File f = new File(outputDirectory + File.separator + name);
                    f.mkdir();
                } else {
                    String fileName = zipEntry.getName();
                    fileName = fileName.replace('\\', '/');
                    if (fileName.indexOf("/") != -1) {
                        createDirectory(outputDirectory, fileName.substring(0,
                                fileName.lastIndexOf("/")));
                        fileName = fileName.substring(
                                fileName.lastIndexOf("/") + 1
                        );
                    }
                    File f = new File(outputDirectory + File.separator
                            + zipEntry.getName());
                    f.createNewFile();
                    try (InputStream in = zipFile.getInputStream(zipEntry); FileOutputStream out = new FileOutputStream(f);) {
                        byte[] by = new byte[1024];
                        int c;
                        while ((c = in.read(by)) != -1) {
                            out.write(by, 0, c);
                        }
                    }

                }
            }

        } catch (Exception ex) {

            System.out.println(ex.getMessage());

        } finally {
            zipFile.close();
        }

    }


    /**
     * @param directory
     * @param subDirectory
     * @Author: yueyiming
     * @Date: 2020/6/17 12:51
     * @return: void
     * @Description: 創建目錄
     **/
    private static void createDirectory(String directory, String subDirectory) {

        String dir[];

        File fl = new File(directory);

        try {

            if (subDirectory == "" && fl.exists() != true) {

                fl.mkdir();

            } else if (subDirectory != "") {

                dir = subDirectory.replace('\\', '/').split("/");

                for (int i = 0; i < dir.length; i++) {

                    File subFile = new File(directory + File.separator + dir[i]);

                    if (subFile.exists() == false)

                        subFile.mkdir();

                    directory += File.separator + dir[i];

                }

            }

        } catch (Exception ex) {

            System.out.println(ex.getMessage());

        }

    }


}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章