Hi,
My application makes a document with two tables in each section, one in the header and one in the body. First it creates the entire body table and creates the header table with a single cell in some rows. It then adds cells of different sizes to the one-cell rows. This last step jumbles the cell sizes in the whole table. See the attached console app made in VS2015 for details. This worked through Words 15.7.0.0 but some subsequent release broke it. The current output is \bin\debug\Example.docx. The desired output, made with Words 15.7.0.0 is \bin\debug\Produced with 15.7.0.0.docx.
Sometimes my app puts both tables into the body and then the tables come out merged. Is that intended behavior? With Words 16 the jumbling extends into the second part of the merged table.
Thanks,
Bill Below
bbelow:
Sometimes my app puts both tables into the body and then the tables come out merged.
Thanks Tahir,
As I was working on the demo console app it occurred to me that since the table width is specified by percent, the column widths should be also. I reworked the demo app to try it out and found that it failed in a way similar (or maybe the same as the. I have attached Program.cs which you can drop into the console app you already have. I think the comments in the code will make it clear what to do. This one fails with version 15.7 also.
Thanks,
Bill Below
int maxtier = 3;
Document doc = new Document();
var builder = new DocumentBuilder(doc);
var ps = builder.PageSetup;
ps.PaperSize = Aspose.Words.PaperSize.Letter;
ps.Orientation = Aspose.Words.Orientation.Landscape;
ps.TopMargin = 36.0;
ps.BottomMargin = 36.0;
ps.LeftMargin = 36.0;
ps.RightMargin = 36.0;
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
Table mtab = new Table(doc);
Row fullrow = MakeTableRow(doc);
for (int k = 0; k < maxtier; k++)
{
if (k < maxtier - 1)
{
var row = new Row(doc);
var cell = new Cell(doc);
cell.CellFormat.PreferredWidth = PreferredWidth.FromPoints(180);
row.Cells.Add(cell);
mtab.Rows.Add(row);
}
else
mtab.Rows.Add(fullrow.Clone(true));
}
// the following 4 lines cause the problem
AddCell(doc, mtab, 0, 540);
AddCell(doc, mtab, 1, 180);
AddCell(doc, mtab, 1, 180);
AddCell(doc, mtab, 1, 180);
// add the table into the document
builder.CurrentStory.AppendChild(mtab);
NodeCollection alltabs = builder.CurrentStory.Tables;
int inx = alltabs.IndexOf(mtab);
mtab.RightPadding = 0.0;
mtab.LeftPadding = 0.0;
mtab.Alignment = TableAlignment.Left;
mtab.AllowAutoFit = false;
// Aspose.Words Call AutoFit(FixedColumnWidths) to update table structure from cell widths after the table construction is complete (no more cells are added).
mtab.AutoFit(AutoFitBehavior.FixedColumnWidths);
// Aspose.Words Set table preferred width after AutoFit() because AutoFit() resets table width to Auto.
mtab.PreferredWidth = PreferredWidth.FromPercent(100);
builder.MoveTo(builder.CurrentSection.Body.FirstParagraph);
Table btab = new Table(doc);
Row brow = MakeTableRow(doc);
for (int j = 0; j < 5; j++)
btab.Rows.Add(brow.Clone(true));
btab.AutoFit(AutoFitBehavior.FixedColumnWidths);
btab.Alignment = TableAlignment.Left;
btab.AllowAutoFit = false;
builder.CurrentSection.Body.AppendChild(btab);
doc.Save(MyDir + "Out v16.3.0.docx");
bbelow:
As I was working on the demo console app it occurred to me that since the table width is specified by percent, the column widths should be also. I reworked the demo app to try it out and found that it failed in a way similar (or maybe the same as the. I have attached Program.cs which you can drop into the console app you already have. I think the comments in the code will make it clear what to do. This one fails with version 15.7 also