Document doc = new Document(@"F:\testing\doc form\original document\11129.docx");
List<String> headings = new List<string>();
foreach (Section sec in doc.Sections)
{
foreach (DocumentObject obj in sec.Body.ChildObjects)
{
// detect if there is heading in paragraph
if (obj is Paragraph)
{
Paragraph par = obj as Paragraph;
string style = par.StyleName;
if (style.Contains("Heading"))
{
headings.Add(par.Text);
}
}
// detect if there is heading in table
if (obj is Table)
{
Table table = obj as Table;
foreach (TableRow row in table.Rows)
{
foreach (TableCell cell in row.Cells)
{
foreach (Paragraph tp in cell.Paragraphs)
{
Paragraph parT = tp as Paragraph;
string Tstyle = parT.StyleName;
if (Tstyle .Contains("Heading"))
{
headings.Add(parT.Text);
}
}
}
}
}
}
}
}
Document doc = new Document(@"F:\testing\doc form\original document\readme123.docx");
List<String> headings = new List<string>();
List<Paragraph> paragraphs = new List<Paragraph>();
foreach (Section sec in doc.Sections)
{
foreach (DocumentObject obj in sec.Body.ChildObjects)
{
if (obj is Paragraph)
{
Paragraph par = obj as Paragraph;
//check if the paragraph is the heading you want
if (par.Text.Contains("ENFORCEABILITY"))
{
headings.Add(par.Text);
int index;
//get the index of the next paragraoh
index = sec.Body.ChildObjects.IndexOf(par) + 1;
for (int i = index; i < sec.Body.ChildObjects.Count; i++)
{
if (sec.Body.ChildObjects[index] is Paragraph)
{
Paragraph Hbody = sec.Body.ChildObjects[index] as Paragraph;
//check if the Hbody is the next "heading"
if (!Hbody.Text.Contains("INVOICING AND PAYMENT"))
{
if(Hbody.Text!= String.Empty)
paragraphs.Add(Hbody);
index++;
}
else
break;
}
}
}
}
}
}
}