I'm writing a program that uses the OpenXML SDK to read OpenXML or Microsoft .docx files, and I've encountered a problem with tables. Because I know a user can create a lot of things, and Word loads, edits, and saves them, I know this is possible. Using Word 2010, I created a table with the following configuration:
This is designed to test horizontal merge, which can be accessed via the GridSpan property, and also vertical merge.
The problem I'm having is that the program can determine whether a cell has a vertical merge--but it cannot tell when that vertical merge ends. There is no RowSpan property for Wordprocessing.TableCell items that reliably lets me answer my question.
Dim objCell as Wordprocessing.TableCell
' Only operates when table cells have a vertical merge property...
If Not IsNothing(objSetup.VerticalMerge) Then
' Only operates if the vertical merge property exists...
If Not IsNothing(objSetup.VerticalMerge.Val) Then
' Sets the starting column number...
intColumn = 1
' Prepares to get the current row...
Dim trRow As Wordprocessing.TableRow
' Obtains the current row...
trRow = objCell.Parent
' Loops through table cells in the current row...
For Each tcCell As Wordprocessing.TableCell In trRow
' Counts the column...
intColumn = intColumn + 1
' Responds if the cell is identified...
If tcCell.OuterXml = objWord.OuterXml Then
' TEST: Notifies the user...
MsgBox("Matching cell found in column " & intColumn & vbCrLf & vbCrLf & objWord.OuterXml)
End If
Next
' TEST: Notifies the user...
MsgBox("Switching to Next Cell")
End If
End If
This program will consistently mistake any table cell with matching height as the current cell, even though the program is part of a loop that reads individual cells from the table, one at a time.
In the upper left corner of this example, where there are three cells with identical row heights, checking one cell will return three cells as "matches." Yes, they span two rows each, but no, the fact that there are three of them means they can't all be the same cell.
Is there any way to identify a specific cell (whether empty or not) in a specific column and a specific row while looping through a table using the OpenXML SDK?
