This project has moved. For the latest updates, please go here.
1
Vote

Tables.Remove Fails

description

I iterate all tables in the document. If one of the table cells contains a special marker, I designate that table as a "debug table" (meaning it will contain information useful to me to debug document generation).

When I set a particular option, I want that "debug table" removed from the final output. The code looks like:
Table debugTable = null;
foreach (Table tbl in doc.Tables)
{                        
    foreach (Row row in tbl.Rows)
    {
        if (tbl == debugTable) break;
        foreach (Cell cell in row.Cells)
        {
            if (tbl == debugTable) break;
            Paragraph para = cell.Paragraphs.First();
            string firstParaText = para.Text;           
            if (firstParaText.Contains("!DEBUG!") && removeDebug)
            {
                debugTable = tbl;
                break;
            }
            // Other processing here
        }
    }
}

if (debugTable != null)
{
    bool success = doc.Tables.Remove(debugTable); // Returns false and the table is not removed
    if (!success) System.Diagnostics.Debug.WriteLine("Could not remove table.");
}
This happens both with the released v1.0.0.12 and with a DLL built from today's source (84071).

comments

BoucherS wrote Apr 27 at 4:40 PM

Hi,

Try using
debugTable.Remove();
instead of
bool success = doc.Tables.Remove(debugTable);