Dear support team,
we’re encountering an inconsistent behavior when calling Aspose.Words.Document.UpdatePageLayout()
, when the document contains 2 tables of different column counts back to back like so:
--------------------------------------------
| table 1 - single column |
--------------------------------------------
| table 2 - column 1 | table 2 - column 2 |
--------------------------------------------
The above representation is what we desire; currently we’re getting the following output though:
---------------------------
| table 1 - single column |
-----------------------------------------------
| table 2 - column 1 | table 2 - column 2 |
-----------------------------------------------
Both tables explicitly specify their Cell.CellFormat.PreferredWith
values to add up to 100%; 100% for each cell of table 1 and 2x 50% for table 2.
Below is the source code of our test cases:
private static String Working_Directory = @".\";
private static Aspose.Words.Document BuildDocument()
{
// Set Aspose words licence:
//AsposeLicenceHelper.SetLicence_Words();
var doc = new Aspose.Words.Document();
var builder = new Aspose.Words.DocumentBuilder(doc);
// First row with 100% width
var table = builder.StartTable();
var cell = builder.InsertCell();
cell.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(100);
builder.Write("row 1 - single cell");
builder.EndTable();
// Last row with 2 cells 50% width each
table = builder.StartTable();
cell = builder.InsertCell();
cell.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(50);
builder.Write("row 2 - cell 1");
cell = builder.InsertCell();
cell.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(50);
builder.Write("row 2 - cell 2");
builder.EndTable();
return doc;
}
[Test]
public static void GenerateTableWithDifferentCellWidths_Test1()
{
var doc = BuildDocument();
doc.Save(Working_Directory + "Test1_working.docx", Aspose.Words.SaveFormat.Docx);
}
[Test]
public static void GenerateTableWithDifferentCellWidths_Test2()
{
var doc = BuildDocument();
doc.UpdatePageLayout();
doc.Save(Working_Directory + "Test2_broken.docx", Aspose.Words.SaveFormat.Docx);
}
[Test]
public static void GenerateTableWithDifferentCellWidths_Test3()
{
var doc = BuildDocument();
doc.Save(Working_Directory + "Test3_working1.docx", Aspose.Words.SaveFormat.Docx);
doc.UpdatePageLayout();
doc.Save(Working_Directory + "Test3_working2.docx", Aspose.Words.SaveFormat.Docx);
}
[Test]
public static void GenerateTableWithDifferentCellWidths_Test4()
{
var doc = BuildDocument();
doc.UpdatePageLayout();
doc.Save(Working_Directory + "Test4_broken1.docx", Aspose.Words.SaveFormat.Docx);
doc.Save(Working_Directory + "Test4_broken2.docx", Aspose.Words.SaveFormat.Docx);
}
Although Test1 works as expected, our production code relies on calling doc.UpdatePageLayout();
for various other reasons, so this won’t be an acceptable solution to us.
Test 2 is the closest test case to our production code, which breaks by only calling doc.UpdatePageLayout();
.
Testcases 3 and 4, we’ve stumbled upon by accident; but the results might still be relevant/helpful in your analysis. Both call doc.Save
twice; but with different positioning of the doc.UpdatePageLayout();
. Proper output in case 3 - for both doc.Save
-calls, when you call the first doc.Save
prior to doc.UpdatePageLayout();
and the second one after that. Calling doc.UpdatePageLayout();
in the beginning though breaks the output for both of the following doc.Save
-calls.
The breaking change must have occurred in Aspose.Words 25.01, because 24.12 is the last version, where all of the above test cases yield the expected result.
Kind regards
Matthias