从word文档中获取文本 [英] Get text from word document

查看:163
本文介绍了从word文档中获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有word文档和数据。我想从word文档数据中获取价值

成本:50.00。在那里我将成本作为输入并使用单词互操作获得50.



我尝试了什么:



我尝试使用匹配的单词,但我没有得到确切的结果或得到整行文字包含

解决方案

以下是您的一些知识:



正常.doc,.docx保存在可以被认为是二进制的内容中 - 即,生成的文本和标记它是一个word文档,就像它们在程序中一样。



通过将文档保存为XML(参见另存为)选项,您可以简化生活。在这种情况下,至少它都是纯文本。但是,你的单词甚至字符可能不在一个块中。这取决于格式。它还取决于数据是否已在Word中修改,因为这本身通常会将更改的文本包装在自己的标记中。



但是 - 如果你在二进制编辑器中查看XML,您可以看到特定文本的包装方式,提取该块,最后清理它以获得您想要的内容。



一个最后一点:如果您(您的用户)将文档打开为.XML,它将保存为.XML,除非他们将其更改回来。


我建​​议从这里开始:

如何:以编程方式搜索和替换文档中的文本 [ ^ ]

如何to:以编程方式在Word中设置搜索选项 [ ^ ]

如何:以编程方式遍历文档中找到的项目 [ ^ ]

Hi,

I have word document with data.I want get value from word document data as
"Cost : 50.00".In that I passing cost as input and get 50 using word interop.

What I have tried:

I try with matching word,but I didn't get exact result or get entire line with text contain

解决方案

Here's some knowledge for you:

Normal .doc, .docx are saved in what can be overall considered binary - i.e., the text and markup that make it a word document are similar to as if they were in a program.

You can make your life easier by saving the documents as XML (see the option in the save-as) listing. In this case, at least it's all in plain-text. HOWEVER, you words and even characters may not be in a single block. This will depend upon formatting. It will also depend on whether the data has been modified in Word, as this, itself, will often wrap the changed text in its own markup.

But - if you look at the XML in a binary editor you can see how your particular text is wrapped, extract that block, and finally clean it up to get what you want.

One last note: if you (you users) open the document as .XML, it will save as .XML unless they change it back.


I'd suggest to start here:
How to: Programmatically Search for and Replace Text in Documents[^]
How to: Programmatically Set Search Options in Word[^]
How to: Programmatically Loop Through Found Items in Documents[^]


这篇关于从word文档中获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆