处理 MS Word 文件中的文本的最简单方法
我需要从 C# 中的旧 MS word .doc 文件中提取文本。 完成这项工作最简单(或者最好)的方法是什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我需要从 C# 中的旧 MS word .doc 文件中提取文本。 完成这项工作最简单(或者最好)的方法是什么?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
首先,您需要添加到 MS Word 对象库中。转到项目 =>添加引用,选择COM选项卡,然后找到并选择“Microsoft Word 10.0对象库”。您计算机上的版本号可能有所不同。单击“确定”。
完成此操作后,您可以使用以下代码。它将打开一个 MS Word 文档,并在消息框中显示每个段落 -
First, you need to add in the MS Word object library. Go to Project => Add Reference, select the COM tab, then find and select "Microsoft Word 10.0 Object Library". The version number might be different on your computer. Click OK.
After you have done that, you can use the following code. It will open up an MS Word doc, and display each paragraph in a message box -
根据您的需求和预算,您可能需要查看 Aspose.Words 库。它并不便宜,但可能会减少提取该文本所需的工作量。好处是您不需要在部署计算机上安装 MSOffice(恕我直言,如果您在服务器上运行它,这是强制性的)。
Depending on your needs and budget you might want to look at the Aspose.Words library. It's not cheap, but might cut down on the effort needed to extract that text. The bonus is that you don't need to have MSOffice installed on your deployment computer (which is mandatory IMHO if you are running this on a server).