Merged cells

J

Jorge

Hi everybody,

I'm developing my own macro to convert a Microsoft Word document in an HTML
document.
Tables with merged cells are a major problem, since I can detect the
existence of merged cells but I cannot identify them. Anyone can give me a
tip?

Thanks

Jorge
 
J

Jezebel

Depends what 'identify them' means for you. You can get some information by
comparing the .Row, .RowIndex, .Column and .ColumnIndex properties.

But the problem is ultimately indeterminate, because there's no underlying
'correct' table from which the merging causing deviations. The table model
is really a somewhat fuzzy beast.

You can create an HTML table from a Word table without reference to cell
merging: just count the number of cells in each row and column, and go from
there.
 
J

Jorge

I'll give you a practical example to clarify my question a bit more:

I get the same properties for a 3x3 table in which Cell(1,3) and Cell(2,3)
are merged and a 3x3 table in which Cell(2,2) and Cell(2,3) are merged.

Certainly, these tables are not the same, so I cannot simply count the
number of rows and columns because I'd end up with the same table in both
cases.
 
J

Jorge

I'll give you a practical example to clarify my question a bit more:

I get the same properties for a 3x3 table in which Cell(1,3) and Cell(2,3)
are merged and a 3x3 table in which Cell(2,2) and Cell(2,3) are merged.

Certainly, these tables are not the same, so I cannot simply count the
number of rows and columns because I'd end up with the same table in both
cases.

Thanks
 
J

Jezebel

That's exactly the point: you end up with the same table either way. And in
HTML, it *IS* the same table either way. What are you actually trying to do?
 
J

Jorge

First of all, thanks for your patience. I must be explaining myself very badly.
The output I want to get for a 3x3 table in which Cell(1,3) and Cell(2,3)
are merged is the following:

<table border="1">
<tr>
<td>Cell 1,1</td>
<td>Cell 1,2</td>
<td rowspan="2">Cell 1,3</td>
</tr>
<tr>
<td>Cell 2,1</td>
<td>Cell 2,2</td>
</tr>
<tr>
<td>Cell 3,1</td>
<td>Cell 3,2</td>
<td>Cell 3,3</td>
</tr>
</table>

The output I want to get for a 3x3 table in which Cell(2,2) and Cell(2,3)
are merged is the following:

<table border="1">
<tr>
<td>Cell 1,1</td>
<td>Cell 1,2</td>
<td>Cell 1,3</td>
</tr>
<tr>
<td>Cell 2,1</td>
<td colspan="2">Cell 2,2</td>
</tr>
<tr>
<td>Cell 3,1</td>
<td>Cell 3,2</td>
<td>Cell 3,3</td>
</tr>
</table>

I'm sorry to insist, these tables have exactly the same number of cells,
rows and columns, but they are not the same because in the first case,
Cell(1,3) occupies two rows and in the second case Cell(2,2) occupies two
columns.
 
J

Jezebel

In both cases you need to maintain an internal model of the 'theoretical'
model of the table, and populate it by examining the cells of the table
individually. This is actually really hard to do: the Word programmers have
never really conquered the problem. The example you give is not too hard,
but consider: take a table with five columns and four rows. Now merge cells
1,1 and 1,2; 2,2 and 2,3; 3,3 and 3,4; 4,4 and 4,5. Now re-align the column
boundaries: do you end up with 4 x 4 table, or a 4 x 5 table with a merged
cell in each row?

This is without even starting on the further complications of split and
deleted cells.

However, for your immediate purposes: you can do the first table by looking
at each cell's .ColumnIndex and .RowIndex properties. You'll see that row 2
has cells in columns 1 and 2 only; therefore its third column must be merged
with the row above. This requires the assumption that the table has not had
cells deleted. (Consider a 3 x 3 table with cell 2,3 deleted from it -- if
that's all that's happened you could tell the difference because .Uniform
would still be true in the latter case.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top