如何读取 MS Word 文档文本框中的文本?

发布于 2024-08-21 21:56:06 字数 216 浏览 5 评论 0原文

我有一个 Word 文档,我想以编程方式将其转换为文本 (.txt) 文件。我为此使用 C#。 我能够从 Word 文档中读取段落和表格并将其转换为文本。 Word文档中有一些文本框,这些文本框包含我想要阅读的文本并将它们放入文本文件中。 我的问题是我不知道这些文本框存储在哪个集合中。例如,所有表格都存储在表格集合中,段落存储在段落集合中。 谁能告诉我如何从这些文本框中读取内容? 如果您需要任何其他信息,请告诉我。

I have an word document which I want to convert to text (.txt) file programmatically. I am using C# for this.
I am able to read paragraphs and tables from word document and convert them to text. There are some textboxes in the word document and those textboxes contain text that I want to read and put them in text file.
My problem is I do not know in which collection those textboxes are stored. For example, all tables are stored in tables collection, paragraphs in paragraphs collection.
Can anyone please tell me how to read from these text boxes?
Please let me know if you need any additional information.

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

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

发布评论

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

评论(1

梓梦 2024-08-28 21:56:06

有文本框和文本框。我非常确定文本框中的任何文本都将属于 Doc.Content 范围。

为了查找文档中的所有文本框架,我使用以下 VBA 代码:

Dim Doc As Document
Dim Range As Range

' Load document

Set Range = Doc.StoryRanges(wdTextFrameStory)
Do Until Range Is Nothing
    ' Do something with Range.Text
    Set Range = Range.NextStoryRange
Loop

There are text boxes and text frames. I'm pretty sure any text inside text boxes will be part of the Doc.Content range.

To find all the text frames in a document, I use this VBA code:

Dim Doc As Document
Dim Range As Range

' Load document

Set Range = Doc.StoryRanges(wdTextFrameStory)
Do Until Range Is Nothing
    ' Do something with Range.Text
    Set Range = Range.NextStoryRange
Loop
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文