zoukankan      html  css  js  c++  java
  • 导出word的另类做法

    一、背景

    项目中经常有导出word的功能,一般用poi来做,但在要求外观较高的情况下,用poi来做基本不能满足需求

    而事实上word除了我们一般使用的模式外,还存在xml、与html模式(你没看错,右键编辑这种word文件,会发现里面是xml或html)

    在这介绍的,就是使用这两种特殊的模式实现导出word

    二、适用场景

    例:项目信息的导出word、各大招聘网站简历的导出

    三、实现

    在项目里,采用的html模式的word

    用word整理一个大概的模板后,用office打开现则文件选择另存为——网页

    xml,是用另存为——word 2003 XML文档

    1、右键编辑,将内容复制到页面里,这时候就可以以页面的形式打开该word了,然后在页面上进行样式的细调(word只支持一些基本的样式),例:

    我在word中加入一个表格

    导出后,把其中内容放到浏览器中,代码如下(好长好长):

    <html xmlns:v="urn:schemas-microsoft-com:vml"
    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:m="http://schemas.microsoft.com/office/2004/12/omml"
    xmlns="http://www.w3.org/TR/REC-html40">
    
    <head>
    <meta http-equiv=Content-Type content="text/html; charset=x-cp20936">
    <meta name=ProgId content=Word.Document>
    <meta name=Generator content="Microsoft Word 14">
    <meta name=Originator content="Microsoft Word 14">
    <link rel=File-List href="测试.files/filelist.xml">
    <!--[if gte mso 9]><xml>
     <o:DocumentProperties>
      <o:Author>Administrator</o:Author>
      <o:LastAuthor>USER-</o:LastAuthor>
      <o:Revision>2</o:Revision>
      <o:TotalTime>1</o:TotalTime>
      <o:Created>2015-06-03T09:22:00Z</o:Created>
      <o:LastSaved>2015-06-03T09:22:00Z</o:LastSaved>
      <o:Pages>1</o:Pages>
      <o:Words>1</o:Words>
      <o:Characters>10</o:Characters>
      <o:Company>MS</o:Company>
      <o:Lines>1</o:Lines>
      <o:Paragraphs>1</o:Paragraphs>
      <o:CharactersWithSpaces>10</o:CharactersWithSpaces>
      <o:Version>14.00</o:Version>
     </o:DocumentProperties>
     <o:CustomDocumentProperties>
      <o:KSOProductBuildVer dt:dt="string">2052-9.1.0.3914</o:KSOProductBuildVer>
     </o:CustomDocumentProperties>
     <o:OfficeDocumentSettings>
      <o:AllowPNG/>
     </o:OfficeDocumentSettings>
    </xml><![endif]-->
    <link rel=themeData href="测试.files/themedata.thmx">
    <link rel=colorSchemeMapping href="测试.files/colorschememapping.xml">
    <!--[if gte mso 9]><xml>
     <w:WordDocument>
      <w:TrackMoves>false</w:TrackMoves>
      <w:TrackFormatting/>
      <w:PunctuationKerning/>
      <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
      <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
      <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
      <w:ValidateAgainstSchemas>false</w:ValidateAgainstSchemas>
      <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
      <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
      <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
      <w:DoNotUnderlineInvalidXML/>
      <w:DoNotPromoteQF/>
      <w:LidThemeOther>EN-US</w:LidThemeOther>
      <w:LidThemeAsian>ZH-CN</w:LidThemeAsian>
      <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
      <w:Compatibility>
       <w:SpaceForUL/>
       <w:BalanceSingleByteDoubleByteWidth/>
       <w:DoNotLeaveBackslashAlone/>
       <w:ULTrailSpace/>
       <w:DoNotExpandShiftReturn/>
       <w:AdjustLineHeightInTable/>
       <w:BreakWrappedTables/>
       <w:SnapToGridInCell/>
       <w:WrapTextWithPunct/>
       <w:UseAsianBreakRules/>
       <w:DontGrowAutofit/>
       <w:DontUseIndentAsNumberingTabStop/>
       <w:FELineBreak11/>
       <w:WW11IndentRules/>
       <w:DontAutofitConstrainedTables/>
       <w:AutofitLikeWW11/>
       <w:HangulWidthLikeWW11/>
       <w:UseNormalStyleForList/>
       <w:DontVertAlignCellWithSp/>
       <w:DontBreakConstrainedForcedTables/>
       <w:DontVertAlignInTxbx/>
       <w:Word11KerningPairs/>
       <w:CachedColBalance/>
       <w:UseFELayout/>
      </w:Compatibility>
      <m:mathPr>
       <m:mathFont m:val="Cambria Math"/>
       <m:brkBin m:val="before"/>
       <m:brkBinSub m:val="&#45;-"/>
       <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]--><!--[if gte mso 9]><xml>
     <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
      DefSemiHidden="true" DefQFormat="false" DefPriority="99"
      LatentStyleCount="267">
      <w:LsdException Locked="false" Priority="0" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
      <w:LsdException Locked="false" Priority="9" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
      <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
      <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
      <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
      <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
      <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
      <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
      <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
      <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
      <w:LsdException Locked="false" Priority="39" Name="toc 1"/>
      <w:LsdException Locked="false" Priority="39" Name="toc 2"/>
      <w:LsdException Locked="false" Priority="39" Name="toc 3"/>
      <w:LsdException Locked="false" Priority="39" Name="toc 4"/>
      <w:LsdException Locked="false" Priority="39" Name="toc 5"/>
      <w:LsdException Locked="false" Priority="39" Name="toc 6"/>
      <w:LsdException Locked="false" Priority="39" Name="toc 7"/>
      <w:LsdException Locked="false" Priority="39" Name="toc 8"/>
      <w:LsdException Locked="false" Priority="39" Name="toc 9"/>
      <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
      <w:LsdException Locked="false" Priority="10" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="Title"/>
      <w:LsdException Locked="false" Priority="0" Name="Default Paragraph Font"/>
      <w:LsdException Locked="false" Priority="11" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
      <w:LsdException Locked="false" Priority="22" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
      <w:LsdException Locked="false" Priority="20" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
      <w:LsdException Locked="false" Priority="59" SemiHidden="false"
       UnhideWhenUsed="false" Name="Table Grid"/>
      <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
      <w:LsdException Locked="false" Priority="1" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
      <w:LsdException Locked="false" Priority="60" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Shading"/>
      <w:LsdException Locked="false" Priority="61" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light List"/>
      <w:LsdException Locked="false" Priority="62" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Grid"/>
      <w:LsdException Locked="false" Priority="63" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 1"/>
      <w:LsdException Locked="false" Priority="64" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 2"/>
      <w:LsdException Locked="false" Priority="65" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 1"/>
      <w:LsdException Locked="false" Priority="66" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 2"/>
      <w:LsdException Locked="false" Priority="67" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 1"/>
      <w:LsdException Locked="false" Priority="68" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 2"/>
      <w:LsdException Locked="false" Priority="69" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 3"/>
      <w:LsdException Locked="false" Priority="70" SemiHidden="false"
       UnhideWhenUsed="false" Name="Dark List"/>
      <w:LsdException Locked="false" Priority="71" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Shading"/>
      <w:LsdException Locked="false" Priority="72" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful List"/>
      <w:LsdException Locked="false" Priority="73" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Grid"/>
      <w:LsdException Locked="false" Priority="60" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
      <w:LsdException Locked="false" Priority="61" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light List Accent 1"/>
      <w:LsdException Locked="false" Priority="62" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
      <w:LsdException Locked="false" Priority="63" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
      <w:LsdException Locked="false" Priority="64" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
      <w:LsdException Locked="false" Priority="65" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
      <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
      <w:LsdException Locked="false" Priority="34" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
      <w:LsdException Locked="false" Priority="29" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
      <w:LsdException Locked="false" Priority="30" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
      <w:LsdException Locked="false" Priority="66" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
      <w:LsdException Locked="false" Priority="67" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
      <w:LsdException Locked="false" Priority="68" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
      <w:LsdException Locked="false" Priority="69" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
      <w:LsdException Locked="false" Priority="70" SemiHidden="false"
       UnhideWhenUsed="false" Name="Dark List Accent 1"/>
      <w:LsdException Locked="false" Priority="71" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
      <w:LsdException Locked="false" Priority="72" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
      <w:LsdException Locked="false" Priority="73" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
      <w:LsdException Locked="false" Priority="60" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
      <w:LsdException Locked="false" Priority="61" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light List Accent 2"/>
      <w:LsdException Locked="false" Priority="62" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
      <w:LsdException Locked="false" Priority="63" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
      <w:LsdException Locked="false" Priority="64" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
      <w:LsdException Locked="false" Priority="65" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
      <w:LsdException Locked="false" Priority="66" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
      <w:LsdException Locked="false" Priority="67" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
      <w:LsdException Locked="false" Priority="68" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
      <w:LsdException Locked="false" Priority="69" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
      <w:LsdException Locked="false" Priority="70" SemiHidden="false"
       UnhideWhenUsed="false" Name="Dark List Accent 2"/>
      <w:LsdException Locked="false" Priority="71" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
      <w:LsdException Locked="false" Priority="72" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
      <w:LsdException Locked="false" Priority="73" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
      <w:LsdException Locked="false" Priority="60" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
      <w:LsdException Locked="false" Priority="61" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light List Accent 3"/>
      <w:LsdException Locked="false" Priority="62" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
      <w:LsdException Locked="false" Priority="63" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
      <w:LsdException Locked="false" Priority="64" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
      <w:LsdException Locked="false" Priority="65" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
      <w:LsdException Locked="false" Priority="66" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
      <w:LsdException Locked="false" Priority="67" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
      <w:LsdException Locked="false" Priority="68" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
      <w:LsdException Locked="false" Priority="69" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
      <w:LsdException Locked="false" Priority="70" SemiHidden="false"
       UnhideWhenUsed="false" Name="Dark List Accent 3"/>
      <w:LsdException Locked="false" Priority="71" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
      <w:LsdException Locked="false" Priority="72" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
      <w:LsdException Locked="false" Priority="73" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
      <w:LsdException Locked="false" Priority="60" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
      <w:LsdException Locked="false" Priority="61" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light List Accent 4"/>
      <w:LsdException Locked="false" Priority="62" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
      <w:LsdException Locked="false" Priority="63" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
      <w:LsdException Locked="false" Priority="64" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
      <w:LsdException Locked="false" Priority="65" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
      <w:LsdException Locked="false" Priority="66" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
      <w:LsdException Locked="false" Priority="67" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
      <w:LsdException Locked="false" Priority="68" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
      <w:LsdException Locked="false" Priority="69" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
      <w:LsdException Locked="false" Priority="70" SemiHidden="false"
       UnhideWhenUsed="false" Name="Dark List Accent 4"/>
      <w:LsdException Locked="false" Priority="71" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
      <w:LsdException Locked="false" Priority="72" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
      <w:LsdException Locked="false" Priority="73" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
      <w:LsdException Locked="false" Priority="60" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
      <w:LsdException Locked="false" Priority="61" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light List Accent 5"/>
      <w:LsdException Locked="false" Priority="62" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
      <w:LsdException Locked="false" Priority="63" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
      <w:LsdException Locked="false" Priority="64" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
      <w:LsdException Locked="false" Priority="65" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
      <w:LsdException Locked="false" Priority="66" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
      <w:LsdException Locked="false" Priority="67" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
      <w:LsdException Locked="false" Priority="68" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
      <w:LsdException Locked="false" Priority="69" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
      <w:LsdException Locked="false" Priority="70" SemiHidden="false"
       UnhideWhenUsed="false" Name="Dark List Accent 5"/>
      <w:LsdException Locked="false" Priority="71" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
      <w:LsdException Locked="false" Priority="72" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
      <w:LsdException Locked="false" Priority="73" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
      <w:LsdException Locked="false" Priority="60" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
      <w:LsdException Locked="false" Priority="61" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light List Accent 6"/>
      <w:LsdException Locked="false" Priority="62" SemiHidden="false"
       UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
      <w:LsdException Locked="false" Priority="63" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
      <w:LsdException Locked="false" Priority="64" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
      <w:LsdException Locked="false" Priority="65" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
      <w:LsdException Locked="false" Priority="66" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
      <w:LsdException Locked="false" Priority="67" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
      <w:LsdException Locked="false" Priority="68" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
      <w:LsdException Locked="false" Priority="69" SemiHidden="false"
       UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
      <w:LsdException Locked="false" Priority="70" SemiHidden="false"
       UnhideWhenUsed="false" Name="Dark List Accent 6"/>
      <w:LsdException Locked="false" Priority="71" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
      <w:LsdException Locked="false" Priority="72" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
      <w:LsdException Locked="false" Priority="73" SemiHidden="false"
       UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
      <w:LsdException Locked="false" Priority="19" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
      <w:LsdException Locked="false" Priority="21" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
      <w:LsdException Locked="false" Priority="31" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
      <w:LsdException Locked="false" Priority="32" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
      <w:LsdException Locked="false" Priority="33" SemiHidden="false"
       UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
      <w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
      <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
     </w:LatentStyles>
    </xml><![endif]-->
    <style>
    <!--
     /* Font Definitions */
     @font-face
        {font-family:宋体;
        panose-1:2 1 6 0 3 1 1 1 1 1;
        mso-font-alt:SimSun;
        mso-font-charset:134;
        mso-generic-font-family:auto;
        mso-font-pitch:variable;
        mso-font-signature:3 680460288 22 0 262145 0;}
    @font-face
        {font-family:宋体;
        panose-1:2 1 6 0 3 1 1 1 1 1;
        mso-font-alt:SimSun;
        mso-font-charset:134;
        mso-generic-font-family:auto;
        mso-font-pitch:variable;
        mso-font-signature:3 680460288 22 0 262145 0;}
    @font-face
        {font-family:"@宋体";
        panose-1:2 1 6 0 3 1 1 1 1 1;
        mso-font-charset:134;
        mso-generic-font-family:auto;
        mso-font-pitch:variable;
        mso-font-signature:3 680460288 22 0 262145 0;}
     /* Style Definitions */
     p.MsoNormal, li.MsoNormal, div.MsoNormal
        {mso-style-unhide:no;
        mso-style-qformat:yes;
        mso-style-parent:"";
        margin:0cm;
        margin-bottom:.0001pt;
        text-align:justify;
        text-justify:inter-ideograph;
        mso-pagination:none;
        font-size:10.5pt;
        mso-bidi-font-size:10.0pt;
        font-family:"Times New Roman","serif";
        mso-fareast-font-family:宋体;
        mso-font-kerning:1.0pt;}
    p.MsoHeader, li.MsoHeader, div.MsoHeader
        {mso-style-unhide:no;
        margin:0cm;
        margin-bottom:.0001pt;
        text-align:justify;
        text-justify:inter-ideograph;
        mso-pagination:none;
        tab-stops:center 207.65pt right 415.3pt;
        layout-grid-mode:char;
        border:none;
        mso-border-alt:none windowtext 0cm;
        padding:0cm;
        mso-padding-alt:1.0pt 4.0pt 1.0pt 4.0pt;
        font-size:9.0pt;
        mso-bidi-font-size:10.0pt;
        font-family:"Times New Roman","serif";
        mso-fareast-font-family:宋体;
        mso-font-kerning:1.0pt;}
    p.MsoFooter, li.MsoFooter, div.MsoFooter
        {mso-style-unhide:no;
        margin:0cm;
        margin-bottom:.0001pt;
        mso-pagination:none;
        tab-stops:center 207.65pt right 415.3pt;
        layout-grid-mode:char;
        font-size:9.0pt;
        mso-bidi-font-size:10.0pt;
        font-family:"Times New Roman","serif";
        mso-fareast-font-family:宋体;
        mso-font-kerning:1.0pt;}
    .MsoChpDefault
        {mso-style-type:export-only;
        mso-default-props:yes;
        mso-fareast-font-family:宋体;}
     /* Page Definitions */
     @page
        {mso-page-border-surround-header:no;
        mso-page-border-surround-footer:no;}
    @page WordSection1
        {size:595.3pt 841.9pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;
        mso-header-margin:42.55pt;
        mso-footer-margin:49.6pt;
        mso-paper-source:0;
        layout-grid:15.6pt;}
    div.WordSection1
        {page:WordSection1;}
    -->
    </style>
    <!--[if gte mso 10]>
    <style>
     /* Style Definitions */
     table.MsoNormalTable
        {mso-style-name:普通表格;
        mso-tstyle-rowband-size:0;
        mso-tstyle-colband-size:0;
        mso-style-noshow:yes;
        mso-style-priority:99;
        mso-style-parent:"";
        mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
        mso-para-margin:0cm;
        mso-para-margin-bottom:.0001pt;
        mso-pagination:widow-orphan;
        font-size:10.0pt;
        font-family:"Times New Roman","serif";}
    table.MsoTableGrid
        {mso-style-name:网格型;
        mso-tstyle-rowband-size:0;
        mso-tstyle-colband-size:0;
        mso-style-priority:59;
        mso-style-unhide:no;
        border:solid windowtext 1.0pt;
        mso-border-alt:solid windowtext .5pt;
        mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
        mso-border-insideh:.5pt solid windowtext;
        mso-border-insidev:.5pt solid windowtext;
        mso-para-margin:0cm;
        mso-para-margin-bottom:.0001pt;
        mso-pagination:widow-orphan;
        font-size:10.0pt;
        font-family:"Times New Roman","serif";}
    </style>
    <![endif]--><!--[if gte mso 9]><xml>
     <o:shapedefaults v:ext="edit" spidmax="1026" fillcolor="#9cbee0"
      strokecolor="#739cc3">
      <v:fill color="#9cbee0" color2="#bbd5f0" type="gradient">
       <o:fill v:ext="view" type="gradientUnscaled"/>
      </v:fill>
      <v:stroke color="#739cc3" weight="1.25pt"/>
     </o:shapedefaults></xml><![endif]--><!--[if gte mso 9]><xml>
     <o:shapelayout v:ext="edit">
      <o:idmap v:ext="edit" data="1"/>
     </o:shapelayout></xml><![endif]-->
    </head>
    
    <body bgcolor=white lang=ZH-CN style='tab-interval:21.0pt;text-justify-trim:
    punctuation'>
    
    <div class=WordSection1 style='layout-grid:15.6pt'>
    
    <table class=MsoNormalTable border=1 cellspacing=0 cellpadding=0
     style='border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt;
     mso-yfti-tbllook:1184;mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-border-insideh:
     .5pt solid windowtext;mso-border-insidev:.5pt solid windowtext'>
     <tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes'>
      <td width=284 valign=top style='213.05pt;border:solid windowtext 1.0pt;
      mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt'>
      <p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";
      mso-hansi-font-family:"Times New Roman"'>测试</span><span lang=EN-US>1</span></p>
      </td>
      <td width=284 valign=top style='213.05pt;border:solid windowtext 1.0pt;
      border-left:none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:
      solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt'>
      <p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";
      mso-hansi-font-family:"Times New Roman"'>笑尽云荒</span></p>
      </td>
     </tr>
    </table>
    
    <p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>
    
    </div>
    
    </body>
    
    </html>

     页面展示为:

    2、在controller层放置要展示的数据,用jstl标签库,在页面进行替换

    3、调整head头

            //下载文件名
            String filename = "";
            filename = projectReleasesList.get(0).getProjectName();
            filename += ".doc";
            //文件名转码,火狐
            if (request.getHeader("User-Agent").toLowerCase().indexOf("firefox") >0){
                filename = new String(filename.getBytes(), "ISO8859-1");
            }
            //非火狐
            else{
                filename = URLEncoder.encode(filename, "UTF-8");
            }
            response.setHeader("Content-disposition", "attachment; filename=" + filename);

    这时,打开这个页面会直接下载XXXX.doc这样一个word文件,该文件用office、wps均可正常打开

  • 相关阅读:
    WPF,Silverlight与XAML读书笔记第二十四 控件之六 – Items控件之菜单&其它
    WPF,Silverlight与XAML读书笔记第二十八 控件之十 – 媒体控件
    WPF,Silverlight与XAML读书笔记第三十一 可视化效果之布局概览 & 尺寸
    WPF,Silverlight与XAML读书笔记第三十 绘图系统概览
    rabbitmq的发布确认和事务
    Windows Server 2008答疑
    C#获取当前所有进程名
    无法在Web服务器上启动调试。调试失败,因为没有启用集成Windows身份认证
    8088 汇编速查手册
    Access保存图片
  • 原文地址:https://www.cnblogs.com/xjyh/p/4549749.html
Copyright © 2011-2022 走看看