How to read WORD

Feb 22, 2014 at 4:31 PM
More in detail, i have a ".docx" WORD with paragraphs and tables, is there any way i can read them using this NPOI one by one?

Say, i have a paragraph "abc" followed with a table, and i want my c# app can read the "abc" and then process the following table. But the truth is that, the paragraph and table are separated, i cannot process them together in order, like the below sample code, i don't know if the "para" followed with a table
using (FileStream stream = File.OpenRead(filepath))
{
    XWPFDocument doc = new XWPFDocument(stream);
    foreach (var para in doc.Paragraphs)
    {
        string text = para.ParagraphText; 
        ...
        var runs = para.Runs;
        string styleid = para.Style;
 
        for (int i = 0; i < runs.Count; i++)
        {
             var run = runs[i];
             text = run.ToString();
            ...
        }
    }
}

var tables = doc.Tables;
 
foreach (var table in tables)
{
 
    foreach (var row in table.Rows) 
    {
        var c0= row.GetCell(0); 
        foreach (var para in c0.Paragraphs)
        {
       string text = para.ParagraphText;
            ...
        }
    }
}
Coordinator
Mar 13, 2014 at 9:34 PM
This is the default behavior of Word. NPOI has no control on it.
Marked as answer by tonyqus on 4/12/2014 at 2:34 PM