使用 C# 识别 ms word 文档中的标题 [英] Identify heading in an ms word document using C#
本文介绍了使用 C# 识别 ms word 文档中的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要分别识别ms word文档中的标题和普通文本,并将它们放在excel表的两个不同列中.这是一个使用 C# 的 VSTO 应用程序.
I need to identify the headings and normal texts in a ms word document separately and put them in two different columns of an excel sheet. This is a VSTO application using C#.
推荐答案
这是单词部分的简短循环.获取段落样式的名称,并检查它的名称.该名称将根据您的文档模板中定义的内容而有所不同.
Here's a short loop for the word part. Get the name of the style for a paragraph, and check it's name. The name will differ according to what is defined in your document template.
foreach (Paragraph paragraph in this.Application.ActiveDocument.Paragraphs)
{
Style style = paragraph.get_Style() as Style;
string styleName = style.NameLocal;
string text = paragraph.Range.Text;
if( styleName == "Normal" ) // do something
else if( styleName == "Heading 1" ) // do something
}
这篇关于使用 C# 识别 ms word 文档中的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文