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.
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--)
for (var index = table.Rows.Cells.Count - 1; index > 2; 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[0, 3 + j].Width = dateWidth;
// add the first row