Quantcast
Channel: NPOI
Viewing all articles
Browse latest Browse all 1621

New Post: How to read WORD

$
0
0
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;
            ...
        }
    }
}

Viewing all articles
Browse latest Browse all 1621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>