About Table width setting

i want to create table with custom width setting, use aspose to test two case , all of case has four columns.
first scenario:
10%, 15%, 55%, 20%

second scenario:
10%, 15%, auto, 20%

in imaging, this two scenario will going to the same result. but is not, below picture show the real result.

table width

below is my test code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

ADoc.Tables.Table tbl = builder.StartTable();
ADoc.Tables.Cell versionCell = builder.InsertCell();
builder.CellFormat.PreferredWidth = ADoc.Tables.PreferredWidth.FromPercent(10); //10%
builder.Write("版本");
ADoc.Tables.Cell authorCell = builder.InsertCell();
builder.CellFormat.PreferredWidth = ADoc.Tables.PreferredWidth.FromPercent(15); //15%
builder.Write("作者");
ADoc.Tables.Cell descCell = builder.InsertCell();
builder.CellFormat.PreferredWidth = ADoc.Tables.PreferredWidth.Auto;
// builder.CellFormat.PreferredWidth = ADoc.Tables.PreferredWidth.FromPercent(55); //55%
builder.Write("更新说明");
ADoc.Tables.Cell datetimeCell = builder.InsertCell();
builder.CellFormat.PreferredWidth = ADoc.Tables.PreferredWidth.FromPercent(20); //15%
builder.Write("时间");
builder.EndRow();
tbl.PreferredWidth = ADoc.Tables.PreferredWidth.FromPercent(100);
for (int i = 0; i < 4; i++) { // insert a blank row
    builder.InsertCell();
}
builder.EndRow();
builder.EndTable();
// tbl.StyleIdentifier = ADoc.StyleIdentifier.TableColumns5;
doc.Save(@"C:\Users\CHN\Desktop\testDoc\" + "out.docx");


the attachment is my standalone testing code.

in use 14.2

both result are all not match imaging, first result is better but the fourth column’s width is so tiny.

Hi,

Thanks for your inquiry. Please add the following line in your code to fix these problems:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table tbl = builder.StartTable();
Cell versionCell = builder.InsertCell();
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(10); //10%
builder.Write("版本");
Cell authorCell = builder.InsertCell();
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(15); //15%
builder.Write("作者");
Cell descCell = builder.InsertCell();
builder.CellFormat.PreferredWidth = PreferredWidth.Auto;
builder.Write("更新说明");
Cell datetimeCell = builder.InsertCell();
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20); //15%
builder.Write("时间");
builder.EndRow();
tbl.PreferredWidth = PreferredWidth.FromPercent(100);
builder.CellFormat.PreferredWidth = PreferredWidth.Auto;
for (int i = 0; i < 4; i++)
{ // insert a blank row
    builder.InsertCell();
}
builder.EndRow();
builder.EndTable();
// tbl.StyleIdentifier = ADoc.StyleIdentifier.TableColumns5;
doc.Save(MyDir + @"out.docx");

I hope, this helps.

Best regards,

hi,Awais

thank you very much. what a magical code.