Hi I am looking for code to add a table to a template with a bookmark:
The first step in my code is to go to the named bookmark, then I generate the table, but the table is not attached to location of the bookmark, but shows at the very end of the document.
var bookmark = bookmarks.FirstOrDefault(b => b.Bookmark.Name == "PricingTable");if (bookmark is not null)
{
editor.MoveToInlineEnd(bookmark.Bookmark.BookmarkRangeStart);
Table table = document.Sections.AddSection().Blocks.AddTable();
document.StyleRepository.AddBuiltInStyle(BuiltInStyleNames.TableGridStyleId);
table.StyleId = BuiltInStyleNames.TableGridStyleId;
foreach (var pricingTableRow in pricingTable)
{
TableRow row = table.Rows.AddTableRow();
foreach (var property in pricingTableRow.GetType().GetProperties())
{
TableCell cell = row.Cells.AddTableCell();
cell.Blocks.AddParagraph().Inlines.AddRun(property.GetValue(pricingTableRow) is null ? string.Empty : property?.GetValue(pricingTableRow)?.ToString());
}
}
}
}