Hi,
I’m trying to insert several Tables into a Document.
This code works fine for one table, but fails for more than one:
private void _insertTable(Table table)
{
foreach (Section sect in _dstDoc.Sections)
{
foreach (Paragraph paragraph in sect.Body.Paragraphs)
{
foreach (Run run in paragraph.Runs)
{
switch (run.Text.Trim())
{
case Globals.ITEMS_RATINGS:
Section sectItemsNew = new Section(_dstDoc);
Body bodyNewItems = new Body(_dstDoc);
sectItemsNew.AppendChild(bodyNewItems);
bodyNewItems.Tables.Add(table);
_dstDoc.InsertBefore(sectItemsNew, sect);
run.Text = "";
break;
case Globals.CATEGORY_SUMMARY:
Section sectCategoryNew = new Section(_dstDoc);
Body bodyCategoryNew = new Body(_dstDoc);
sectCategoryNew.AppendChild(bodyCategoryNew);
bodyCategoryNew.Tables.Add(table);
_dstDoc.InsertAfter(sectCategoryNew, sect);
run.Text = "";
break;
}
}
}
}
}
Also tried this code, but again it fails for more than one table:
private void _insertTable(Table table)
{
foreach (Section sect in _dstDoc.Sections)
{
foreach (Paragraph paragraph in sect.Body.Paragraphs)
{
foreach (Run run in paragraph.Runs)
{
switch (run.Text.Trim())
{
case Globals.ITEMS_RATINGS:
sect.Body.InsertAfter(table, paragraph);
sect.Body.InsertBefore(table, paragraph);
sect.Body.Tables.Insert();
paragraph.Remove();
run.Text = "";
break;
case Globals.CATEGORY_SUMMARY:
sect.Body.Tables.Add(table);
sect.Body.InsertAfter(table, paragraph);
sect.Body.InsertBefore(table, paragraph);
paragraph.Remove();
run.Text = "";
break;
}
}
}
}
}
Thanks,
Ophir