Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

We have a requirement to read Word documents which is like template. This word document is having multiple tables. We can able to read normal tables but application is throwing exception if a table is having vertically merge cells.

Can some body help with the code.

Thanks in advance
Murali krishna.
Posted
Updated 22-May-15 2:35am
v2

1 solution

The only way that we have found is to do
var myDictionary<int,> = new Dictionary<int,>();
var cell = myTable.Cell(1, 1);

while(cell != null)
{
    // Cache the line
    myDictionary[cell.ColumnIndex] = cell.Range.Text;

    // The second part is so we don't display if we just started
    if(cell.ColumnIndex == 1 && cell.RowIndex != 1)
    {
        Trace.WriteLine("Data at row {0} is:", cell.RowIndex);
        foreach(KeyValuePair<int,> kvp in myDictionary)
        {
            Trace.WriteLine("    Column({0}) --> {1})", kvp.Key, kvp.Value);
        }
        Trace.WriteLine("");// or output a \n
    }

    // Move to the next *valid* cell
    // cell.Next skips cells that merged and already looked at
    cell = cell.next
}


To keep track of what was in the previous cell, we used a dictionary and cleared it whenever we got to the first column of the next row.

This code won't show the last row but it gives you the idea
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900