如何从Word文档中提取RTF/HTML文本?

发布于 2024-07-27 02:12:08 字数 269 浏览 1 评论 0原文

上下文:我使用 Microsoft 发布的 DSOFramer 示例将 Word 嵌入到 Winforms 中。 现在,我可以使用 Word 文档的所有格式选项编写文本。

问题:我可以使用 doc.Content.Text 从文档中提取基本文本(doc 是对我的 Word 文档的引用),但我不知道如何获取带格式的文本,无论是 RTF 还是 as HTML。 我希望 Word 文档具有类似于 RichTextBox 中的 Rtf 属性的内容,但似乎并非如此。 那么我该如何获取格式化文本呢?

Context : I embedded Word into a Winforms using the DSOFramer sample published by Microsoft. Now, I can write text with all formatting options of a Word document.

Question : I can extract the basic text from the doc, using doc.Content.Text (doc is a reference to my Word document), but i can't figure out how I can get the text with formatting, either as RTF or as HTML. I hopped Word docs had something similar to the Rtf attribute in the RichTextBox, but it doesn't seem so. So how am I supposed to get the formatted text ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱*していゐ 2024-08-03 02:12:08

您可以使用剪贴板:

Microsoft.Office.Interop.Word.Document doc = 
    axFramerControl1.ActiveDocument as Microsoft.Office.Interop.Word.Document;
doc.Content.Select();
doc.Content.Copy();
this.richTextBox1.Paste();

You can use the clipboard:

Microsoft.Office.Interop.Word.Document doc = 
    axFramerControl1.ActiveDocument as Microsoft.Office.Interop.Word.Document;
doc.Content.Select();
doc.Content.Copy();
this.richTextBox1.Paste();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文