Free Support Forum - aspose.com

The edge of cell inserted by aspose.word compoennt align with the cell bellow it automatically

Recently, when we upgraded from Word 2003 to 2016, We encountered a very crazy problem. When I inserted cells in any a middle row of the table, its boundaries automatically aligned with the cells corresponding to the next row, even if I set the width of the new cell base on the property “PreferredWidth” as bellow .

nc.CellFormat.PreferredWidth = PreferredWidth.FromPoints(50 );

But it word at Word 2003, the attachment is the result of using Aspose. Word to process two versions of the document. Actually, That extension of document is ‘.doc’ is the result what we wanted .

We purchased the aspose.total license end of 2018.11 and use aspose.word which version is 17.9 . in our system .word.zip (16.9 KB)

      Aspose.Words.Document doc = new Aspose.Words.Document(@"C:\Users\Administrator\Desktop\UPF AATCC 183-2004.docx", new Aspose.Words.LoadOptions() { LoadFormat = LoadFormat.Docx});
        DocumentBuilder db = new DocumentBuilder(doc);
        Cell nc = new Cell(doc);
        nc.CellFormat.PreferredWidth = PreferredWidth.FromPoints(50 );
        Paragraph pg = new Paragraph(doc );
        pg.Runs.Add(new Run(doc) { Text = "New Cell"});
        nc.AppendChild(pg);
        Table tb = doc.Sections[0].Body.Tables[0];
        tb.Rows[2].Cells.Insert(2, nc);
        doc.Save(@"C:\Users\Administrator\Desktop\UPF AATCC 183-2004-1.docx", SaveFormat.Docx);

@wengyeung

Thanks for your inquiry. Please try the latest version of Aspose.Words for .NET 18.11. Hope this helps you.

If you still face problem, please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

Thanks for your reply , Unfortunately,the problem still exits after i replaced the newest component of Aspose.Wod by your ref. , the attachment is the input document , please help to process it , thanks again .

UPF AATCC 183-2004.zip (13.1 KB)

@wengyeung

Thanks for sharing the detail. Please call Table.AutoFit(AutoFitBehavior.FixedColumnWidths) method before saving document to get the desired output.

Please check the following code example.

Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "UPF AATCC 183-2004.docx");
DocumentBuilder db = new DocumentBuilder(doc);
Cell nc = new Cell(doc);
nc.CellFormat.PreferredWidth = PreferredWidth.FromPoints(50);
Paragraph pg = new Paragraph(doc);
pg.Runs.Add(new Run(doc) { Text = "New Cell" });
nc.AppendChild(pg);
Table tb = doc.Sections[0].Body.Tables[0];
tb.Rows[2].Cells.Insert(2, nc);

tb.AutoFit(AutoFitBehavior.FixedColumnWidths);
doc.Save(MyDir + "18.11.docx");