5

我是一个学习者Microsoft.Office.Interop.Word。考虑一下我有一个带有“Header1”样式标题的word文档,下面有一些“正常”样式的句子。现在我需要找到属于样式“标题 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
    }
}

如何显示这些标题下的所有行?

4

1 回答 1

2

我想你想要这样的东西,假设我理解你的问题:

//get the 'next' paragraph but only if it exists
if (paragraph.Next() != null)
{
     MessageBox.Show("Next paragraph:" + paragraph.Next().Range.Text.ToString());
}
于 2012-06-30T06:37:27.300 回答