使用C#从word文档中提取所需的文本 [英] Extract required text from word document using C#

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

问题描述

任何人都可以告诉我如何使用C#从Word文档中仅提取所需的文本。



关于Word文档:



Word文档包含一些简单的文本和音频文本,我想区分并从word doc中提取文本到excel。



故事板屏幕截图链接包含简单的文本和音频文本,您可以在其中看到2种文本颜色蓝色和黑色。问题是识别黑色文本,因为它有一些简单的文本和音频文本,我希望将文本放入Excel中的单独列中,如上面的屏幕截图链接所示。



我可以将Word文档中的文本提取到Excel中,但问题是如何在不改变字体样式和颜色的情况下识别简单文本和音频文本。



任何帮助都将受到高度赞赏。



提前致谢。



什么我试过了:



我遵循了2种方法,但这些不适合我 -

1.单独添加将书签标记为每个文本的标识符,以便我们可以轻松识别和提取文本。

2.更改我们要提取的文本的字体样式和颜色。

但这些方法是时间,而不是一个适合我的解决方案,所以任何人都可以有另一个想法来识别不同的文本,请建议。

Can anyone tell me how to extract only required text from Word document using C#.

About Word document:

Word document contains some simple text and audio text and I want to differentiate and extract that text from word doc into excel.

Storyboard Screen shot link contains Simple text and audio text and where you can see 2 Text colors Blue and Black. Problem is to identify the Black color Text because it has some Simple Text and Audio Text and I want that Text into Excel in separate columns as displayed in Screen shot link above.

and i'm able to extract the text from Word document into Excel but problem is how can I identify Simple text and Audio text without changing the font style and color.

Any help in this will be highly appreciated.

Thanks in advance.

What I have tried:

I have followed 2 approaches but these are not appropriate solution for me-
1. Add separate Bookmark as identifier for each Text so that we can identify and extract the text easily.
2. Change font style and colour of the text we want to extract.
but these approaches are time taking and not a proper solution for me so any one can have another idea to identify the different text please suggest.

解决方案

您可以尝试将Word文档保存为HTML文件,然后使用Jquery提取彩色元素。但是,您必须对生成的HTML文件进行2次修改。



1.插入jQuery CDN脚本

You could try saving the Word document as an HTML file and then use Jquery to extract the colored elements. Though, you will have to make 2 modifications to the generated HTML file.

1. Insert jQuery CDN script
<script src="https://code.jquery.com/jquery-3.0.0.min.js" integrity="sha256-JmvOoLtYsmqlsWxa7mDSLMwa6dZ9rrIdtrrVYRnDRH0=" crossorigin="anonymous"></script>





2.插入自定义jQuery代码。



2. Insert Custom jQuery code.

var texts =


' span'< /跨度>);
var fin = [];
('span'); var fin = [];


.each(texts,功能(i,v){
if
.each(texts, function(i,v){ if(


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

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