I need to programmatically add and remove rows from a Word 2010 table. Unfortunately, the table header contains merged cells, both horizontally and vertically. This causes an error when using the Row.Add and Row.Delete methods. I checked and found that I can programmatically delete the merged cells (Cell.Split), and then execute the .Add and .Delete methods, and then restore the merged cells. The problem I am facing is to determine which cells are merged.
------------------------- | 1,1 | 1,2 | 1,3 | 1,4 | ------------------------- | 2,1 | 2,2 | 2,3 | 2,4 | -------------------------
If cells 1,1 and 2,1 are vertically merged, then access to Table.Cell (2,1) causes an error. And this is good. But if cells 1,1 and 1,2 are horizontally merged, access 1,2 does not cause an error, but access to 1,4 does. This means that I cannot determine which cells are horizontally merged.
What I'm trying to do is let developers change the look of the Word document, but the data in the table is populated with an SQL query that people populate with a web application.
My question is, is there a way to determine the layout of the table so that I can remove the merged cells and recreate them after adding and removing rows?
Thanks Aaron
Aaron source share