I have a table with 2 rows: the first one is the header and the 2nd is a "template row" which I need to repeat replacing some placeholder text with meaningful data.
In pseudo-code it would be something like this:
var templateRow = table.Rows.Last();
foreach (var currentRecord in records)
// the following overload doesnt exist and would create a new row
// with the same contents as the row passed as parameter
var newRow = table.InsertRow(templateRow);
// this method would call ReplaceText on newRow as required
I already have something that works but it is very "hacky".
I use this code to clone the template row:
var internalRowCtor = typeof (Row).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).Single();
var list = templateRow.Cells.Select(cell => CloneElement(cell.Xml)).ToList();
var newRow = (Row)internalRowCtor.Invoke(new object
new XElement(XName.Get("tr", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"), list)
then do the replacement thing and then this other snippet to add it at the end of the table:
Any help would be very welcomed.