Hi, I have following problem: I open existing documet and then want to insert table into it (using DocumentBuilder). When I do so, table is fit to window (as in MS Word setting AutoFit to window) but I need it to be fit to content (like using AutoFit to contents). It behaves same even if I set RowFormat.AllowAutoFit to true.
But when I insert table into empty document created with words, everything works fine.
Code is very simle
DocumentBuilder bu = new DocumentBuilder(doc);
bu.StartTable();
bu.InsertCell();
bu.Write(“aa”);
bu.InsertCell();
bu.Write(“bb”);
bu.EndRow();
bu.InsertCell();
bu.Write(“cc”);
bu.InsertCell();
bu.Write(“dd”);
bu.EndRow();
bu.EndTable();
Do you have any idea?
Alexander Simko
Hi Alexander,
Could you please attach the document in question?
Hi,
Here is the file.
Alexander Simko
The issue seems tricky. Please hold on - I need one more day for reseacrch.
The issue itself seems to be rather complex, but the following code seems to solve the problem nicely in my test:
builder.RowFormat.ClearFormatting();
builder.RowFormat.AllowAutoFit = true;
builder.StartTable();
builder.InsertCell();
builder.CellFormat.Width = 1;
builder.Write("aa");
builder.InsertCell();
builder.CellFormat.Width = 1;
builder.Write("bb");
builder.EndRow();
builder.InsertCell();
builder.Write("cc");
builder.InsertCell();
builder.Write("dd");
builder.EndRow();
builder.EndTable();