Hi,
I am using a template document, with a formatted table in a bookmark. I can find the table and then change it.
However, I would like to start with a fixed set of rows and columns.
When using
table.ResetCells(1, 2);
It also clears the content of the cells. There does not seem to be an option to retain the content when doing ResetCells. So what is the best alternative?
I now do this, please check if this is the most efficient. Perhaps I should make an extension method?
First step is reduce to 1 row and just a few cells to ensure the unwanted columns and cell content is removed:
if (table== null) return;
//reduce to just the header
for (var index = table.Rows.Count - 1; index > 0; index--)
{
table.Rows.Remove(table.Rows[index]);
}
for (var index = table.Rows[0].Cells.Count - 1; index > 2; index--)
{
table.Rows[0].Cells.RemoveAt(index);
}
Next expand the number of columns dynamically to the desired, and add the first content row to be filled:
//add the needed cells for the dates
for (int j = 0; j <= dateCount; j++)
{
table.Rows[0].Cells.Add(new WTableCell(_wordDocument));
table[0, 3 + j].Width = dateWidth;
}
// add the first row
table.AddRow(true, true);
Thanks, Pieter