We encountered a new problem when I split the columns of the table below into multiple columns which version of Aspose.Word component is 24.09 . Then invoke the method table.AutoFit(AutoFitBehavior.FixedColumnWidths); to calculate whole table .
At runtime, I saw that the copied columns had the same column width, but after saving the document by using method as bellow
(table.Document as Document ).Save("c:\\temp\\1.docx")
the width of the last column of the cell changed. However, I noticed that the Preferred With value of its cell was the same as the values of the other copied columns on the left ,as bellow screenshot .
and the final document as bellow
SIO_Size.docx (17.8 KB)
and the original document as bellow
SIO_Size.docx (23.7 KB)
@wengyeung
Summary
When you split a table’s columns and then call table.AutoFit(AutoFitBehavior.FixedColumnWidths), the column widths look correct in memory, but after saving the document the last column’s visual width changes.
Why it happens
- In the 24.09 release the layout engine updates column widths lazily.
AutoFit sets the preferred widths of the individual cells, but the overall table layout is not forced to recalculate before the document is serialized. During the save operation the table can be re‑flowed, causing the final column to stretch to fill any remaining space.
- Structural changes such as cell splitting do not automatically trigger a layout refresh in this version, leading to a mismatch between the in‑memory state and the saved file.
- Later releases (≥ 25.x) contain improvements that make the layout refresh automatic, but a workaround is still required when staying on 24.09.
What to do next
- Force a layout update before saving
// … code that splits cells …
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
// Recalculate the layout so the column widths are fixed
doc.UpdatePageLayout(); // forces layout refresh
// Save the document
doc.Save(@"C:\temp\1.docx");
- Define an explicit total width for the table (recommended)
// Set the overall table width (adjust the value to your page layout)
table.PreferredWidth = PreferredWidth.FromPoints(500);
table.PreferredWidthType = PreferredWidthType.Point;
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
doc.UpdatePageLayout();
doc.Save(@"C:\temp\1.docx");
Specifying the table’s total width prevents Word from automatically expanding the last column to fill the page.
- Consider upgrading the Aspose.Words library
If an upgrade is feasible, test the same code with a newer version (e.g., 25.x). The layout engine in later releases performs the refresh automatically, which often eliminates the issue.
If upgrading is not possible, the two steps above should provide a reliable workaround.
- Provide a minimal reproducible sample if the problem persists
- A short snippet that shows the cell‑splitting logic (
Table.SplitCell, Row.Cells.Add, any width assignments).
- A small DOCX file (a single‑page table) that reproduces the width change after saving.
With such a sample we can run an internal verification and, if needed, log a product issue for version 24.09.
- Verify the behavior in other output formats (optional)
Save the same document to PDF or HTML. If the width discrepancy appears only in DOCX, it points to a serialization‑related layout refresh problem; consistent results across formats suggest a broader layout issue.
Follow steps 1–2 first; they usually resolve the column‑width shift. If the issue remains, share the minimal sample so we can investigate further.
I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.
@wengyeung Could you please provide a simple code that will allow us to reproduce the problem? We will check the issue and provide you more information.