如何转换System.IO.Packaging.Package为HTML?IO、System、Packaging、HTML

2023-09-03 20:29:57 作者:泅渡

Microsoft Word中的互操作性类可以让你在a物业名为 WordOpenXML 。这再presents将被存储在一个封装 - 压缩了 - 在的.docx 文件,并可以通过Microsoft Word中打开。但是,有没有办法这个转换为其他格式,特别是HTML?

我读an回答以一个老问题了Word 2007中有一个你可以用它来转换为HTML的API。[...]你可以找到周围的API文档,但我记得有一个转换为HTML功能该API。我不是100%肯定它的API,男人在谈论,但也许这是 System.IO.Packaging.Package 或类似的东西。我似乎无法找到任何转换为HTML功能;没有人知道如何转换格式的Word文档转换为HTML?

解决方案

在讨论的API可能是对文件的保存方法;当HTML的文件类型选择时,Word转换的文档转换为HTML,并应用适当的样式。

有机会,鉴于 DOCX 格式是XML,有某种事情的XSLT转换;这仅仅是猜测,但它不是牵强,因为XSLT通常用于创建XML HTML。

组态 PROFINET IO 系统的 IRT 通讯

这是说,你在找什么大概会的没有的驻留在的 类,也不应该。该类是用于创建的内容包,不与内容的转变。

但是,并没有什么东西提供该内容的转型阻止你;你可以是Word文档的基础上的XML,然后应用自己的XSLT这将产生所需的HTML。

Microsoft Word interoperability classes will let you get at a property called WordOpenXML. This represents a package that will be stored - zipped up - in a .docx file and can be opened by Microsoft Word. However, is there a way to convert this Package to other formats, notably HTML?

I read in an answer to an old question that "Word 2007 has an API that you can use to convert to HTML. [...] You can find documentation around the API, but I remember that there is a convert to HTML function in the API." I'm not 100% sure which API that guy is talking about but perhaps it's System.IO.Packaging.Package or something similar. I can't seem to find any "convert to HTML function"; does anyone know how you can convert a Package format Word document into HTML?

解决方案

The API in question is probably the Save method on the document; when a file type of HTML is chosen, Word transforms the document into HTML, and applies the appropriate styling.

Chances are, given that the docx format is XML, there is an XSLT transformation of some sort going on; this is just speculation, but it's not far-fetched, as XSLT is commonly used to create HTML from XML.

That said, what you are looking for probably does not reside in the Package class, nor should it. The Package class is used for creating packages of content, not with the transformation of that content.

However, there's nothing stopping you from providing the transformation of that content; you can get the XML that is the basis of the Word document and then apply your own XSLT which would produce the HTML that you want.