Width Bug for Cell with Column Span

I’ve attached my project. When the first column is set to a width
of 15%, the “test” row is cut short and doesn’t span the entire
table. I believe when a cell spans more than one column, its
width should be calculated based on cells in adjacent rows.
Here’s what I’m doing in the code:



’ Set the cell width

Call subSetCellWidth(stStateInfo.getAttributeValue(“style”))



’ If this cell spans more than one column, create new cells and merge with previous

If Not IsNothing(stStateInfo.getAttributeValue(“COLSPAN”)) Then

nColspan = CInt(stStateInfo.getAttributeValue(“COLSPAN”))

nCounter = nColspan

If nColspan > 1 Then

wrdDocBuilder.CellFormat.HorizontalMerge = CellMerge.First

Call subAdjustCellIndex(nColspan)

While (nCounter <> 1)

wrdDocBuilder.InsertCell()

wrdDocBuilder.CellFormat.HorizontalMerge = CellMerge.Previous

nCounter -= 1

End While

wrdDocBuilder.MoveToCell(nGetTableIndex(), nGetRowIndex(), nGetColumnIndex(nColspan), 0)

End If

End If



As you can see, I’m setting the width of the cell with the
colspan. Then I’m creating enough cells to create the necessary
colspan amount. Then I move the pointer back to the cell with the
colspan value. This is actually quite a hassle…is there a
better way of handling column span?



Thanks, Natan.

Thanks for reporting the issue. I’ll check what could be done.

As far as I can see you are writing your own HTML import, probably because Aspose.Word's HTML import does not support import of cell width in percent. This is feature is being worked on right now and might become available in the next few weeks.

Roman,



After exploring the problem further, I now see that it goes beyond the
scope of column span. For example, if a table has 3 columns and
the table’s width is 500, then it’s the programmer’s responsibility to
ensure that the total width for all columns does not exceed 500.



Do you have any plans to improve your own table processing code so that programmers don’t have to write all this logic?



Thanks, Natan.

Roman,



I’ve found a quick way to reproduce the problem with column spanning
and column width. Build a table with 3 rows and 4 columns.
Set the table width to 500 and the cell widths for rows 1 and 3 as
follows:



1st Cell = 100, 2nd Cell = 100, 3rd Cell = 100, 4th Cell = 200



Set the 1st cell of the 2nd row to span 4 columns. The problem is
that I can’t find a good width to set for the cell that spans 4
columns. Should the width be 100 (matching the first cell of
other rows)? Should the width be 125 (500 / 4 columns)? Or
should the width be 500 (the entire length of the table)?



I’ve attached an updated version of my project. Input1 will show
you what happens when the width = 100, input 2 for width = 125, input3
for width = 500. All width values produce unsatisfactory results.



Thanks, Natan.

Any updates for this issue? The width problem is affecting a good number of our reports.



Thanks, Natan.

Support for import of cell widths from HTML is almost finished. We are through the final paces.

I’m actually reporting a different problem but attached it to this thread a couple posts up. Here’s the recap:




I’ve found a quick way to reproduce the problem with column spanning
and column width. Build a table with 3 rows and 4 columns.
Set the table width to 500 and the cell widths for rows 1 and 3 as
follows:



1st Cell = 100, 2nd Cell = 100, 3rd Cell = 100, 4th Cell = 200



Set the 1st cell of the 2nd row to span 4 columns. The problem is
that I can’t find a good width to set for the cell that spans 4
columns. Should the width be 100 (matching the first cell of
other rows)? Should the width be 125 (500 / 4 columns)? Or
should the width be 500 (the entire length of the table)?



I’ve attached an updated version of my project. Input1 will show
you what happens when the width = 100, input 2 for width = 125, input3
for width = 500. All width values produce unsatisfactory results.



I’ve attached my project again.



Thanks, Natan.

I just created a 4th input where I don’t set the cell width at all if it spans more than one column and that didn’t work either.



Have you been able to reproduce this bug?



Thanks, Natan.

It works okay either way for me. To form a table whose left and right sides are properly aligned you just need to make sure that sum of cell widths in each row is the same.

Also, since you are playing with merged columns, make sure you reset the cell merge attribute when finished.

This code works for me and produces a nicely aligned table. I even added borders to check if borders contribute to the difference you are getting. Looks like they don't.

[Test]

public void TestX()

{

builder.StartTable();

builder.InsertCell();

builder.CellFormat.Width = 100;

builder.Write("Cell1");

builder.InsertCell();

builder.Write("Cell2");

builder.InsertCell();

builder.Write("Cell3");

builder.InsertCell();

builder.CellFormat.Width = 200;

builder.Write("Cell4");

builder.EndRow();

builder.InsertCell();

builder.CellFormat.Width = 500;

builder.CellFormat.HorizontalMerge = CellMerge.First;

builder.Write("Cell5");

builder.InsertCell();

builder.CellFormat.Width = 0;

builder.CellFormat.HorizontalMerge = CellMerge.Previous;

builder.Write("Cell5");

builder.InsertCell();

builder.CellFormat.Width = 0;

builder.CellFormat.HorizontalMerge = CellMerge.Previous;

builder.Write("Cell5");

builder.InsertCell();

builder.CellFormat.Width = 0;

builder.CellFormat.HorizontalMerge = CellMerge.Previous;

builder.Write("Cell5");

builder.EndRow();

builder.InsertCell();

builder.CellFormat.Width = 100;

builder.CellFormat.HorizontalMerge = CellMerge.None;

builder.CellFormat.Borders[BorderType.Left].LineStyle = LineStyle.Single;

builder.CellFormat.Borders[BorderType.Left].LineWidth = 3;

builder.CellFormat.Borders[BorderType.Left].Color = Color.Black;

builder.Write("Cell6");

builder.InsertCell();

builder.Write("Cell7");

builder.InsertCell();

builder.Write("Cell8");

builder.InsertCell();

builder.CellFormat.Width = 200;

builder.Write("Cell9");

builder.EndRow();

builder.EndTable();

TestUtil.Save(doc, @"DocBuilder\Table\TestX Out.doc");

}

Roman,

Thanks for checking this out. It makes sense that the cell that spans 4 columns should get a width of 500. For some reason, when I set it 500, the output is corrupted (input3.xml from my project).

I'll run some tests again just to make sure every width is set correctly. Could you take a look at input3 and see if I'm missing anything?

Thanks, Natan.

Roman,



Based on your code, I solved the problem and realized what I was doing
wrong. The key is the following line of code for columns that
have CellMerge.Previous set:



DocumentBuilder.CellFormat.Width = 0



I had thought the default width of a cell was 0 but it’s actually
72. Please add all this to your documentation on how to handle
column spanning (if you haven’t already).



Thanks!