以编程方式将 html 表格标记转换为 MS Word 表格
我有一个存储在变量中的 html 表的标记。它基本上包含表格的开始和结束标记:
<table>
<tr>
...
</tr>
.
.
</table>
我需要它在我的 Word 文档中显示为表格。当然,我的word文档是通过编程“打开”的; word文档还有其他部分需要填写。我只想在文档的某个部分插入此表。
如果人们给我一些如何实现这一目标的指导,我将不胜感激?我正在寻找一些 .net 代码来做同样的事情。
I've got a markup for a html table stored in a variable. It will basically contain the start and end tag for a table:
<table>
<tr>
...
</tr>
.
.
</table>
I need this to appear as a table in my word document. Of course, my word document is programmatically "open"; there are other sections to fill in the word document. Its only at a certain section in the document I want to insert this table.
Would appreciate if people gave me some directions on how to achieve this? I am looking for some .net code to do the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 altChunk,前提是文档要在 Word 中打开(因为 Word 将执行转换 HTML 的工作)。创建文档时不需要Word;只用于打开它。
就 Microsoft 的 OpenXML SDK 类而言:您需要 AlternativeFormatImportPart 类型为 AlternativeFormatImportPartType.Html 或 Xhtml,或者如果您的表中有图像,Mht。
请参阅http://sunnyhasan.blogspot.com/ 2010/04/html-to-word-document-converter-using.html 或 http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/d8595e50-76f6-42ab-a7d7-7bfc92a3655e/ 例如
You can use an altChunk, provided the document is to be opened in Word (since Word will do the work to convert the HTML). Word is not required at the time the document is created; only for opening it.
In terms of Microsoft's OpenXML SDK classes: you want AlternativeFormatImportPart of type AlternativeFormatImportPartType.Html or Xhtml or if you have images in your table, Mht.
See http://sunnyhasan.blogspot.com/2010/04/html-to-word-document-converter-using.html or http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/d8595e50-76f6-42ab-a7d7-7bfc92a3655e/ for examples