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

Free Support Forum - aspose.com

Two tables, second with merged cells, join different after updating from 15.3

Hi,

after updating from 15.3 to 18.1 (latest version allowed by license) there is an issue with tables that join by themself.

I have attached a project which demonstrates the issue as well as 3 documents which are created with different versions. One with 15.3 where everything looks good, another one with 18.1, where the issue starts to appear and latest we can use, and 19.5, the latest available, which still has the issue.

AsposeTableIssue2.zip (29.6 KB)

Thanks for your help.

Br
TK

@torstenklier

Please use the following modified code to get the desired output. Hope this helps you.

var doc = new Document();
doc.Sections[0].PageSetup.PaperSize = Aspose.Words.PaperSize.A4;
doc.Sections[0].PageSetup.BottomMargin = 25.5;
doc.Sections[0].PageSetup.TopMargin = 25.5;
doc.Sections[0].PageSetup.LeftMargin = 34;
doc.Sections[0].PageSetup.RightMargin = 28.35;

var builder = new DocumentBuilder(doc);

double tableWidth = 0;

var table = builder.StartTable();
for (int i = 0; i < 6; i++)
{
    var cell = builder.InsertCell();
    cell.CellFormat.Width = ConvertUtil.MillimeterToPoint(20);
    tableWidth += cell.CellFormat.Width;
    builder.Write($"R1C{i + 1}");
}

builder.EndRow();
builder.EndTable();

table.AutoFit(AutoFitBehavior.FixedColumnWidths);
                
//Insert empty paragraph after table. 
Paragraph paragraph = builder.InsertParagraph();

var table2 = builder.StartTable();
var cell21 = builder.InsertCell();
cell21.CellFormat.Width = tableWidth / 2;
builder.Write("R2C1");

var cell22 = builder.InsertCell();
cell22.CellFormat.Width = tableWidth - cell21.CellFormat.Width;
builder.Write("R2C2");

builder.EndRow();
builder.EndTable();

table2.AutoFit(AutoFitBehavior.FixedColumnWidths);
doc.UpdatePageLayout();

//remove the inserted paragraph
table2.PreviousSibling.Remove();
doc.Save(MyDir + "19.5.docx");

Thanks, this helps.

Does this call have any side effects?

I use some object model to describe a document and later have some classes that produce me a word document from it.

So, it could happen that this method is called while building nested tables and is also called multiple times while creating the full document.

Saving to different formats is also a separate step so I have no information while creation of the document what format it is later saved as. I read that this method should be called before saving as pdf. My test shows me that calling the method after removing the paragraph keeps the document as it is, fortunately.

Can you also give me a hint if this changed behaviour is intentional?

I mean the output is really different and if I had not decoupled document description from document creation, I would have to change a lot of code. For me it looks like a bug. I specify that my cell should be 20mm and because of the join of the second table it is raised to 60mm.

@torstenklier

Please note that Aspose.Words mimics the behavior of MS Word. It is not a bug. If you create same tables using MS Word, insert a paragraph break between them, and remove the paragraph. You will get the same correct output.

In your case, you are merging the tables without inserting the paragraph between them. You need to set the cell’s width of first and second rows after merging the table to get the desired output.

You may use the approach share in my previous post to get the desired output.