Take the 2-minute tour ×

The below code reads the paragraph under each heading in a word document untill a carriage return is reached. Am not able to read the paragraphs after carriage return but still under the same heading. Is there a way to accomplish this. Can any1 tell me if its feasible.

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.Trim();
    string[] words = text.Split('.');

    if (styleName.Contains("Heading") 
        || styleName.Contains("Heading1") 
        || styleName.Contains("Heading2") 
        || styleName.Contains("Heading3"))
        foreach (string word in words)
            if(paragraph.Next() !=null)
                int j = 1;
                string data = paragraph.Next().Range.Text.ToString().Trim();
                // string h = paragraph.Next().Range.Tables.ToString().Trim();
                string[] dataf = data.Split('.');
                foreach (string dat in dataf)
                    paracount.Add(word + j, dat);
share|improve this question
What would happen to text of other styles, say style "Normal" which I'd expect to follow the headings? –  Emmad Kareem Nov 14 '13 at 10:02
Am reading text following the heading as paragraph. If style is normal it goes out of the loop. If style is heading , it gets all paragraphs under heading until a new line or escape character is encountered. –  Robin Nov 15 '13 at 6:20
how do i read normal style text under heading? –  Robin Nov 15 '13 at 6:55
I know this can be done via access to XML as in msdn.microsoft.com/en-us/library/ff686712%28v=office.14%29.aspx but I am not sure how it is done via Interop. –  Emmad Kareem Nov 15 '13 at 7:40
think its not feasible. even am not finding any way to continue with it. –  Robin Nov 15 '13 at 7:51
add comment


Your Answer



Browse other questions tagged or ask your own question.