none
Select particular paragraph text in Word document RRS feed

  • Question

  • Hi,

    I want to copy particular paragraph and its inner text before the next paragraph in a word document by using paragraph heading number and then paste it to another document.

    When I iterate on all paragraphs it treats all text line and each table cells as a paragraph, I've tried the following code to find paragraph text but it gives only paragraph text not its inner text(means before the next paragraph sibling)

     foreach (Microsoft.Office.Interop.Word.Paragraph aPar in Globals.ThisAddIn.docm.Paragraphs)
     {                
                    Microsoft.Office.Interop.Word.Range parRng = aPar.Range;
                    MessageBox.Show(parRng.Text);                              
     }

    Thanks,

    Saurabh

      
    Friday, November 29, 2013 12:37 PM

Answers

  • Hello Saurabh0571,

    As you probably noticed, the required info (paragraph numbers) is not stored in the text. You may try to get the style applied to a particular paragraph and then use the ListLevelNumber property. Also the OutlineLevel property of the Paragraph class can help.

    Frankly speaking there is no need to use additional properties if you just want to copy the content of a paragraph to a new document. You just need to use a special paste method:

    range.Copy();            
    oDoc1.Content.PasteSpecial(Word.WdPasteOptions.wdKeepSourceFormatting);

     
    Saturday, November 30, 2013 10:20 PM

All replies

  • For more understanding the problem, you can see this docx file: SampleDocx
    Friday, November 29, 2013 12:46 PM
  • Hello Saurabh0571,

    As you probably noticed, the required info (paragraph numbers) is not stored in the text. You may try to get the style applied to a particular paragraph and then use the ListLevelNumber property. Also the OutlineLevel property of the Paragraph class can help.

    Frankly speaking there is no need to use additional properties if you just want to copy the content of a paragraph to a new document. You just need to use a special paste method:

    range.Copy();            
    oDoc1.Content.PasteSpecial(Word.WdPasteOptions.wdKeepSourceFormatting);

     
    Saturday, November 30, 2013 10:20 PM