Determine if Word cell is merged

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

+2
source share
3 answers

Well, I ended up describing the layout of the table in Table Properties / Alt Text / Decription. And then, after reading that in the code, break the cells, delete the rows, and then iterate over the cells. Crude, but it works.

0
source

When working with tables that may contain merged cells, you always need to start with CELL (1,1) and go through the cells with CELL.NEXT (Next is a property of the CELL object)

If you do, you can interrogate which row and column the current cell is in. You + cannot + refer to cells by col directly in tables with merged cells, or you will receive an error message.

Then just continue until NEXT returns anything.

+2
source

You will have to abandon the merge until you figured out all the records.

Word does not work with tables.

I suggest you create an Excel workbook and link the worksheet from the Excel workbook to a Word document. Excel is best suited for spreadsheets.

0
source

Source: https://habr.com/ru/post/1333260/


All Articles