5

私はを使用することの学習者ですMicrosoft.Office.Interop.Word。スタイル「Header1」の見出しが付いた単語ドキュメントがあり、スタイル「normal」の文がその下にあるとします。次に、スタイル「ヘッダー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 に答える