We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Table cell width in footer

I have been using Aspose Words for many years. Thank you for the fine product. However, a change occurred recently that breaks the rendering of tables in footers.



I need a two-row table where the first row has a single cell that is page-width, and the second row has three cells that are each one-third of the page wide. Recent versions of Words renders the first row correctly, but the first cell of the second row appears as page-width rather than the specified fixed column width.



It worked great in version 15.7, but has not worked in versions since then, including the current version 15.11.



I have attached a small piece of code that works correctly in 15.7, but not in 15.11.



Any ideas of settings I can change to get the proper output? Or when a fix might be published?



Thanks.

Hi Jerry,


Thanks for your inquiry. We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-12839. Our product team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,
Hi Jerry,

Thanks for being patient. Regarding WORDSNET-12839, our product team has completed the work on your issue and has come to a conclusion that this issue and the undesired behavior you're observing in latest versions of Aspose.Words is actually not a bug. So, we will close this issue as 'Not a Bug'.

Starting from the version 15.8.0 of Aspose.Words, the new table layout algorithm is used. The old algorithm merged table cells depending on their widths, but the new algorithm does not perform any cell merging. You should merge cells explicitly in code. You should add other two cells into the first row and merge them with the first one. Here is changed code for the first table row in your example:

Dim doc As Aspose.Words.Document = New Aspose.Words.Document

Dim rpt As Aspose.Words.DocumentBuilder = New Aspose.Words.DocumentBuilder(doc)

rpt.MoveToSection(0)

rpt.Writeln("This is body text.")

rpt.MoveToHeaderFooter(Aspose.Words.HeaderFooterType.FooterPrimary)

Dim xTable As Aspose.Words.Tables.Table = Nothing

Dim xCell As Aspose.Words.Tables.Cell = Nothing

rpt.StartTable()

xCell = rpt.InsertCell()

xTable = CType(xCell.GetAncestor(Aspose.Words.NodeType.Table), Aspose.Words.Tables.Table)

xTable.AutoFit(Aspose.Words.Tables.AutoFitBehavior.FixedColumnWidths)

xCell.CellFormat.Width = 2.1 * 72

xCell.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.First

rpt.Write("WIDE FOOTER CELL")

xCell = rpt.InsertCell()

xCell.CellFormat.Width = 2.3 * 72

xCell.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.Previous

xCell = rpt.InsertCell()

xCell.CellFormat.Width = 2.1 * 72

rpt.EndRow()

xCell = rpt.InsertCell()

xCell.CellFormat.Width = 2.1 * 72

xCell.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None

rpt.Write("Left footer cell")

xCell = rpt.InsertCell()

xCell.CellFormat.Width = 2.3 * 72

rpt.Write("Center footer cell")

xCell = rpt.InsertCell()

xCell.CellFormat.Width = 2.1 * 72

rpt.Write("Right footer cell")

rpt.EndRow()

rpt.EndTable()

doc.Save(MyDir & "16.1.0.docx")


Note that CellMerge.Previous is not set for the third cell because of the document builder clones properties of each new cell from the previous one. HorizontalMerge should be set to CellMerge.None for the first cell of the second row. Hope, this helps.

Best regards,

Thank you for the response. However, I am disappointed in your proposed solution.



You address my specific scenario, but it appears that I cannot have different width cells on adjacent rows in a table. If I want the first row to have a single 3-inch cell and the second row to have three 2-inch cells, your solution will not work.



Merging cells and having multiple cell widths are two separate issues.



I hope there is a solution that allows every cell to have its own width, independent of other cells. And each row to have a different number of cells and different row width than adjacent rows. I believe this is how Microsoft Word operates, but it seems to be different in Aspose Words.



Thanks.

Hi Jerry,


Thanks for your inquiry.
Jerry:
but it appears that I cannot have different width cells on adjacent rows in a table. If I want the first row to have a single 3-inch cell and the second row to have three 2-inch cells, your solution will not work.

Merging cells and having multiple cell widths are two separate issues.

I hope there is a solution that allows every cell to have its own width, independent of other cells. And each row to have a different number of cells and different row width than adjacent rows. I believe this is how Microsoft Word operates, but it seems to be different in Aspose Words.
Please try using the following code:

Dim doc As Document = New Document

Dim builder As DocumentBuilder = New DocumentBuilder(doc)

Dim tab = builder.StartTable()

builder.InsertCell()

builder.Writeln("Row 1 Cell 1")

builder.CellFormat.Width = 3 * 72

builder.EndRow()

builder.InsertCell()

builder.Writeln("Row 2 Cell 1")

builder.CellFormat.Width = 2 * 72

builder.InsertCell()

builder.Writeln("Row 2 Cell 2")

builder.CellFormat.Width = 2 * 72

builder.InsertCell()

builder.Writeln("Row 2 Cell 3")

builder.CellFormat.Width = 2 * 72

builder.EndRow()

builder.EndTable()

doc.Save(MyDir & "16.1.0.docx")


Hope, this helps.

Best regards,