This project has moved and is read-only. For the latest updates, please go here.

Tables.Remove Fails


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;
            // 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).


BoucherS wrote Apr 27, 2017 at 4:40 PM


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