【问题标题】:Export From HTML To MS Word从 HTML 导出到 MS Word
【发布时间】:2011-01-05 22:01:56
【问题描述】:

如何使用 VB.NET 在 ASP.NET 中将 HTML 保存为 Microsoft Word 文档?我需要一个特殊的库来执行转换吗?

【问题讨论】:

    标签: asp.net html vb.net ms-word


    【解决方案1】:

    您可以使用 Office 自动化或尝试自己生成本机文件格式。但是,我可以推荐使用专门的库来完成这项工作。我自己使用了一个库来导出 Excel,很高兴有一个合适的 .NET 对象模型来操作,而不是了解本机文件结构。节省大量时间和工作。 Aspose 可能有适合您的组件或库。

    【讨论】:

      【解决方案2】:

      你可以将页眉中的内容类型更改为application/vnd.ms-word,这样就可以了,这当然是最简单的方法,我相信还有其他方法。

      【讨论】:

        【解决方案3】:

        考虑到 MS Word 可以直接读取 HTML,您只需将 Response.ContentType 更改为 application/ms-word。

        但是,如果您想要创建一个.doc 文件,您可能需要查看Office Automation。

        另一种方法是创建一个 XML MS-Word 文件,但这会限制您使用 Word 2003 及更高版本。

        例如下面的 XML 是一个保存在 word XML 文件中的 Empty 文档。

        <?xml version="1.0" encoding="utf-8" standalone="yes"?>
        <?mso-application progid="Word.Document"?>
        <w:wordDocument 
          xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
          xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
          xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:o="urn:schemas-microsoft-com:office:office"
          xmlns:v="urn:schemas-microsoft-com:vml"
          xmlns:w10="urn:schemas-microsoft-com:office:word"
          xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
          xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
          xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2"
          xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core"
          w:macrosPresent="no" 
          w:embeddedObjPresent="no" 
          w:ocxPresent="no"
          xml:space="preserve">
        <w:ignoreSubtree w:val="http://schemas.microsoft.com/office/word/2003/wordml/sp2" />
        <o:DocumentProperties>
          <o:Author>Paulo Santos</o:Author>
          <o:LastAuthor>Paulo Santos</o:LastAuthor>
          <o:Revision>1</o:Revision>
          <o:TotalTime>0</o:TotalTime>
          <o:Created>2010-01-16T19:09:00Z</o:Created>
          <o:LastSaved>2010-01-16T19:09:00Z</o:LastSaved>
          <o:Pages>1</o:Pages>
          <o:Words>0</o:Words>
          <o:Characters>0</o:Characters>
          <o:Company>PJ on Development</o:Company>
          <o:Lines>1</o:Lines>
          <o:Paragraphs>1</o:Paragraphs>
          <o:CharactersWithSpaces>0</o:CharactersWithSpaces>
          <o:Version>12</o:Version>
        </o:DocumentProperties>
        <w:fonts>
          <w:defaultFonts w:ascii="Calibri" w:fareast="Calibri"
          w:h-ansi="Calibri" w:cs="Times New Roman" />
          <w:font w:name="Times New Roman">
            <w:panose-1 w:val="02020603050405020304" />
            <w:charset w:val="00" />
            <w:family w:val="Roman" />
            <w:pitch w:val="variable" />
            <w:sig w:usb-0="E0002AFF" w:usb-1="C0007841" w:usb-2="00000009"
            w:usb-3="00000000" w:csb-0="000001FF" w:csb-1="00000000" />
          </w:font>
          <w:font w:name="Cambria Math">
            <w:panose-1 w:val="02040503050406030204" />
            <w:charset w:val="01" />
            <w:family w:val="Roman" />
            <w:notTrueType />
            <w:pitch w:val="variable" />
            <w:sig w:usb-0="00000000" w:usb-1="00000000" w:usb-2="00000000"
            w:usb-3="00000000" w:csb-0="00000000" w:csb-1="00000000" />
          </w:font>
          <w:font w:name="Calibri">
            <w:panose-1 w:val="020F0502020204030204" />
            <w:charset w:val="00" />
            <w:family w:val="Swiss" />
            <w:pitch w:val="variable" />
            <w:sig w:usb-0="E10002FF" w:usb-1="4000ACFF" w:usb-2="00000009"
            w:usb-3="00000000" w:csb-0="0000019F" w:csb-1="00000000" />
          </w:font>
        </w:fonts>
        <w:styles>
          <w:versionOfBuiltInStylenames w:val="7" />
          <w:latentStyles w:defLockedState="off" w:latentStyleCount="267">
            <w:lsdException w:name="Normal" />
            <w:lsdException w:name="heading 1" />
            <w:lsdException w:name="heading 2" />
            <w:lsdException w:name="heading 3" />
            <w:lsdException w:name="heading 4" />
            <w:lsdException w:name="heading 5" />
            <w:lsdException w:name="heading 6" />
            <w:lsdException w:name="heading 7" />
            <w:lsdException w:name="heading 8" />
            <w:lsdException w:name="heading 9" />
            <w:lsdException w:name="toc 1" />
            <w:lsdException w:name="toc 2" />
            <w:lsdException w:name="toc 3" />
            <w:lsdException w:name="toc 4" />
            <w:lsdException w:name="toc 5" />
            <w:lsdException w:name="toc 6" />
            <w:lsdException w:name="toc 7" />
            <w:lsdException w:name="toc 8" />
            <w:lsdException w:name="toc 9" />
            <w:lsdException w:name="caption" />
            <w:lsdException w:name="Title" />
            <w:lsdException w:name="Default Paragraph Font" />
            <w:lsdException w:name="Subtitle" />
            <w:lsdException w:name="Strong" />
            <w:lsdException w:name="Emphasis" />
            <w:lsdException w:name="Table Grid" />
            <w:lsdException w:name="Placeholder Text" />
            <w:lsdException w:name="No Spacing" />
            <w:lsdException w:name="Light Shading" />
            <w:lsdException w:name="Light List" />
            <w:lsdException w:name="Light Grid" />
            <w:lsdException w:name="Medium Shading 1" />
            <w:lsdException w:name="Medium Shading 2" />
            <w:lsdException w:name="Medium List 1" />
            <w:lsdException w:name="Medium List 2" />
            <w:lsdException w:name="Medium Grid 1" />
            <w:lsdException w:name="Medium Grid 2" />
            <w:lsdException w:name="Medium Grid 3" />
            <w:lsdException w:name="Dark List" />
            <w:lsdException w:name="Colorful Shading" />
            <w:lsdException w:name="Colorful List" />
            <w:lsdException w:name="Colorful Grid" />
            <w:lsdException w:name="Light Shading Accent 1" />
            <w:lsdException w:name="Light List Accent 1" />
            <w:lsdException w:name="Light Grid Accent 1" />
            <w:lsdException w:name="Medium Shading 1 Accent 1" />
            <w:lsdException w:name="Medium Shading 2 Accent 1" />
            <w:lsdException w:name="Medium List 1 Accent 1" />
            <w:lsdException w:name="Revision" />
            <w:lsdException w:name="List Paragraph" />
            <w:lsdException w:name="Quote" />
            <w:lsdException w:name="Intense Quote" />
            <w:lsdException w:name="Medium List 2 Accent 1" />
            <w:lsdException w:name="Medium Grid 1 Accent 1" />
            <w:lsdException w:name="Medium Grid 2 Accent 1" />
            <w:lsdException w:name="Medium Grid 3 Accent 1" />
            <w:lsdException w:name="Dark List Accent 1" />
            <w:lsdException w:name="Colorful Shading Accent 1" />
            <w:lsdException w:name="Colorful List Accent 1" />
            <w:lsdException w:name="Colorful Grid Accent 1" />
            <w:lsdException w:name="Light Shading Accent 2" />
            <w:lsdException w:name="Light List Accent 2" />
            <w:lsdException w:name="Light Grid Accent 2" />
            <w:lsdException w:name="Medium Shading 1 Accent 2" />
            <w:lsdException w:name="Medium Shading 2 Accent 2" />
            <w:lsdException w:name="Medium List 1 Accent 2" />
            <w:lsdException w:name="Medium List 2 Accent 2" />
            <w:lsdException w:name="Medium Grid 1 Accent 2" />
            <w:lsdException w:name="Medium Grid 2 Accent 2" />
            <w:lsdException w:name="Medium Grid 3 Accent 2" />
            <w:lsdException w:name="Dark List Accent 2" />
            <w:lsdException w:name="Colorful Shading Accent 2" />
            <w:lsdException w:name="Colorful List Accent 2" />
            <w:lsdException w:name="Colorful Grid Accent 2" />
            <w:lsdException w:name="Light Shading Accent 3" />
            <w:lsdException w:name="Light List Accent 3" />
            <w:lsdException w:name="Light Grid Accent 3" />
            <w:lsdException w:name="Medium Shading 1 Accent 3" />
            <w:lsdException w:name="Medium Shading 2 Accent 3" />
            <w:lsdException w:name="Medium List 1 Accent 3" />
            <w:lsdException w:name="Medium List 2 Accent 3" />
            <w:lsdException w:name="Medium Grid 1 Accent 3" />
            <w:lsdException w:name="Medium Grid 2 Accent 3" />
            <w:lsdException w:name="Medium Grid 3 Accent 3" />
            <w:lsdException w:name="Dark List Accent 3" />
            <w:lsdException w:name="Colorful Shading Accent 3" />
            <w:lsdException w:name="Colorful List Accent 3" />
            <w:lsdException w:name="Colorful Grid Accent 3" />
            <w:lsdException w:name="Light Shading Accent 4" />
            <w:lsdException w:name="Light List Accent 4" />
            <w:lsdException w:name="Light Grid Accent 4" />
            <w:lsdException w:name="Medium Shading 1 Accent 4" />
            <w:lsdException w:name="Medium Shading 2 Accent 4" />
            <w:lsdException w:name="Medium List 1 Accent 4" />
            <w:lsdException w:name="Medium List 2 Accent 4" />
            <w:lsdException w:name="Medium Grid 1 Accent 4" />
            <w:lsdException w:name="Medium Grid 2 Accent 4" />
            <w:lsdException w:name="Medium Grid 3 Accent 4" />
            <w:lsdException w:name="Dark List Accent 4" />
            <w:lsdException w:name="Colorful Shading Accent 4" />
            <w:lsdException w:name="Colorful List Accent 4" />
            <w:lsdException w:name="Colorful Grid Accent 4" />
            <w:lsdException w:name="Light Shading Accent 5" />
            <w:lsdException w:name="Light List Accent 5" />
            <w:lsdException w:name="Light Grid Accent 5" />
            <w:lsdException w:name="Medium Shading 1 Accent 5" />
            <w:lsdException w:name="Medium Shading 2 Accent 5" />
            <w:lsdException w:name="Medium List 1 Accent 5" />
            <w:lsdException w:name="Medium List 2 Accent 5" />
            <w:lsdException w:name="Medium Grid 1 Accent 5" />
            <w:lsdException w:name="Medium Grid 2 Accent 5" />
            <w:lsdException w:name="Medium Grid 3 Accent 5" />
            <w:lsdException w:name="Dark List Accent 5" />
            <w:lsdException w:name="Colorful Shading Accent 5" />
            <w:lsdException w:name="Colorful List Accent 5" />
            <w:lsdException w:name="Colorful Grid Accent 5" />
            <w:lsdException w:name="Light Shading Accent 6" />
            <w:lsdException w:name="Light List Accent 6" />
            <w:lsdException w:name="Light Grid Accent 6" />
            <w:lsdException w:name="Medium Shading 1 Accent 6" />
            <w:lsdException w:name="Medium Shading 2 Accent 6" />
            <w:lsdException w:name="Medium List 1 Accent 6" />
            <w:lsdException w:name="Medium List 2 Accent 6" />
            <w:lsdException w:name="Medium Grid 1 Accent 6" />
            <w:lsdException w:name="Medium Grid 2 Accent 6" />
            <w:lsdException w:name="Medium Grid 3 Accent 6" />
            <w:lsdException w:name="Dark List Accent 6" />
            <w:lsdException w:name="Colorful Shading Accent 6" />
            <w:lsdException w:name="Colorful List Accent 6" />
            <w:lsdException w:name="Colorful Grid Accent 6" />
            <w:lsdException w:name="Subtle Emphasis" />
            <w:lsdException w:name="Intense Emphasis" />
            <w:lsdException w:name="Subtle Reference" />
            <w:lsdException w:name="Intense Reference" />
            <w:lsdException w:name="Book Title" />
            <w:lsdException w:name="Bibliography" />
            <w:lsdException w:name="TOC Heading" />
          </w:latentStyles>
          <w:style w:type="paragraph" w:default="on" w:styleId="Normal">
            <w:name w:val="Normal" />
            <w:rsid w:val="001F679D" />
            <w:pPr>
              <w:spacing w:after="200" w:line="276" w:line-rule="auto" />
            </w:pPr>
            <w:rPr>
              <wx:font wx:val="Calibri" />
              <w:sz w:val="22" />
              <w:sz-cs w:val="22" />
              <w:lang w:val="EN-US" w:fareast="EN-US" w:bidi="AR-SA" />
            </w:rPr>
          </w:style>
          <w:style w:type="character" w:default="on"
          w:styleId="DefaultParagraphFont">
            <w:name w:val="Default Paragraph Font" />
          </w:style>
          <w:style w:type="table" w:default="on" w:styleId="TableNormal">
            <w:name w:val="Normal Table" />
            <wx:uiName wx:val="Table Normal" />
            <w:rPr>
              <wx:font wx:val="Calibri" />
              <w:lang w:val="EN-US" w:fareast="EN-US" w:bidi="AR-SA" />
            </w:rPr>
            <w:tblPr>
              <w:tblInd w:w="0" w:type="dxa" />
              <w:tblCellMar>
                <w:top w:w="0" w:type="dxa" />
                <w:left w:w="108" w:type="dxa" />
                <w:bottom w:w="0" w:type="dxa" />
                <w:right w:w="108" w:type="dxa" />
              </w:tblCellMar>
            </w:tblPr>
          </w:style>
          <w:style w:type="list" w:default="on" w:styleId="NoList">
            <w:name w:val="No List" />
          </w:style>
        </w:styles>
        <w:shapeDefaults>
          <o:shapedefaults v:ext="edit" spidmax="2050" />
          <o:shapelayout v:ext="edit">
            <o:idmap v:ext="edit" data="1" />
          </o:shapelayout>
        </w:shapeDefaults>
        <w:docPr>
          <w:view w:val="print" />
          <w:zoom w:percent="100" />
          <w:doNotEmbedSystemFonts />
          <w:defaultTabStop w:val="720" />
          <w:punctuationKerning />
          <w:characterSpacingControl w:val="DontCompress" />
          <w:optimizeForBrowser />
          <w:validateAgainstSchema />
          <w:saveInvalidXML w:val="off" />
          <w:ignoreMixedContent w:val="off" />
          <w:alwaysShowPlaceholderText w:val="off" />
          <w:compat>
            <w:breakWrappedTables />
            <w:snapToGridInCell />
            <w:wrapTextWithPunct />
            <w:useAsianBreakRules />
            <w:dontGrowAutofit />
          </w:compat>
          <wsp:rsids>
            <wsp:rsidRoot wsp:val="0063767C" />
            <wsp:rsid wsp:val="001F679D" />
            <wsp:rsid wsp:val="0063767C" />
          </wsp:rsids>
        </w:docPr>
        <w:body>
          <w:p wsp:rsidR="001F679D" wsp:rsidRDefault="001F679D" />
          <w:sectPr wsp:rsidR="001F679D" wsp:rsidSect="001F679D">
            <w:pgSz w:w="12240" w:h="15840" />
            <w:pgMar w:top="1440" w:right="1440" w:bottom="1440"
            w:left="1440" w:header="720" w:footer="720" w:gutter="0" />
            <w:cols w:space="720" />
            <w:docGrid w:line-pitch="360" />
          </w:sectPr>
        </w:body>
        </w:wordDocument>
        

        您可能不需要上面看到的所有项目,但这是可行的。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-13
          • 2021-09-24
          • 1970-01-01
          相关资源
          最近更新 更多