freemarker html转word输出问题

问题一: 转为word后不分页问题
解决办法: 将下面代码添加到要分页的位置即可

<span><br clear=all style = 'page-break-before:always' ></span>

问题二: 转换为word后默认视图变为了web视图,想要设置默认视图为页面视图
解决办法: 用下面的代码替换html和head头即可

<html xmlns:o="urn:schemas-microsoft-com:office:office" 
    xmlns:w="urn:schemas-microsoft-com:office:word"
    xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" 
    xmlns="http://www.w3.org/TR/REC-html40">
<head>
      <!--[if gte mso 9]>
        <xml>
            <w:WordDocument>
            <w:View>Print</w:View>
            <w:TrackMoves>false</w:TrackMoves>
            <w:TrackFormatting/>
            <w:ValidateAgainstSchemas/>
            <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
            <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
            <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
            <w:DoNotPromoteQF/>
            <w:LidThemeOther>EN-US</w:LidThemeOther>
            <w:LidThemeAsian>ZH-CN</w:LidThemeAsian>
            <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
            <w:Compatibility>
                <w:BreakWrappedTables/>
                <w:SnapToGridInCell/>
                <w:WrapTextWithPunct/>
                <w:UseAsianBreakRules/>
                <w:DontGrowAutofit/>
                <w:SplitPgBreakAndParaMark/>
                <w:DontVertAlignCellWithSp/>
                <w:DontBreakConstrainedForcedTables/>
                <w:DontVertAlignInTxbx/>
                <w:Word11KerningPairs/>
                <w:CachedColBalance/>
                <w:UseFELayout/>
            </w:Compatibility>
            <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
            <m:mathPr>
                <m:mathFont m:val='Cambria Math'/>
                <m:brkBin m:val='before'/>
                <m:brkBinSub m:val='--'/>
                <m:smallFrac m:val='off'/>
                <m:dispDef/><m:lMargin m:val='0'/> 
                <m:rMargin m:val='0'/><m:defJc m:val='centerGroup'/>
                <m:wrapIndent m:val='1440'/>
                <m:intLim m:val='subSup'/>
                <m:naryLim m:val='undOvr'/>
            </m:mathPr>
            </w:WordDocument>
        </xml><![endif]-->
posted @ 2025-04-24 14:41  br-vst  阅读(17)  评论(0)    收藏  举报