Dol*_*olo 5 c# ms-word office-interop
我是使用Microsoft.Office.Interop.Word. 考虑到我有一个标题为“Header1”样式的 word 文档,并且它下面包含一些“normal”样式的句子。现在我需要找到属于“Header 1”样式段落的那些行。这是我被编码的原因:
foreach (Microsoft.Office.Interop.Word.Paragraph paragraph in doc.Paragraphs)
{
Microsoft.Office.Interop.Word.Style style = paragraph.get_Style() as Microsoft.Office.Interop.Word.Style;
string styleName = style.NameLocal;
string text = paragraph.Range.Text;
if (styleName == "Heading 1")
{
MessageBox.Show("Sent lines :" + text.ToString()); //this will show all headings
}
}
Run Code Online (Sandbox Code Playgroud)
如何显示这些标题下的所有行?
我想你想要这样的东西,假设我理解你的问题:
//get the 'next' paragraph but only if it exists
if (paragraph.Next() != null)
{
MessageBox.Show("Next paragraph:" + paragraph.Next().Range.Text.ToString());
}
Run Code Online (Sandbox Code Playgroud)