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

Free Support Forum - aspose.com

Insert Table in Word Document & Set Auto Fit Behavior to Fixed Column Widths (C# .NET)

Hi,

I created document with table. Cell width is percent value. When I used method AutoFit(AutoFitBehavior.FixedColumnWidths) table width is broken - table is very narrow. Without this method table looks okay.
See the sample program:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
    
var table = builder.StartTable();
var cel1 = builder.InsertCell();
cel1.CellFormat.PreferredWidth = PreferredWidth.FromPercent(27);
var cel2 = builder.InsertCell();
cel2.CellFormat.PreferredWidth = PreferredWidth.FromPercent(21);
var cel3 = builder.InsertCell();
cel3.CellFormat.PreferredWidth = PreferredWidth.FromPercent(17);
var cel4 = builder.InsertCell();
cel4.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);
var cel5 = builder.InsertCell();
cel5.CellFormat.PreferredWidth = PreferredWidth.FromPercent(15);
    
table.PreferredWidth = PreferredWidth.FromPercent(100);
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
    
doc.Save(@"Test.docx");

We’re using Aspose.Words for .Net v21.6.0.

Thanks,
Monika

@acturisaspose,

Please note that when you specify AutoFitBehavior.FixedColumnWidths option, then Aspose.Words will disable the Table.AllowAutoFit option and remove the preferred width from the table. However, the widths of the cells will remain as they are specified by their Width properties.