Free Support Forum - aspose.com

Table missplaced

Hello,

I have a word document which I use as a template. In this template I have header, footer, a table and some text. I try to insert a new table at a certain position, but the table is sometimes inserted right after the existing table from the template (attached to the existing table).

I use next code to insert the table. The merge field is used for specifying the correct position for the table, but however the table is placed somewhere else. I've attached the template too.

DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToMergeField("Quote_items_table");

builder.StartTable();

builder.RowFormat.Height = 0.4 * 72; //0.4"

builder.RowFormat.HeightRule = HeightRule.Exactly;

//It is possible to change cell format before (like here) and also during creation of the cell.

builder.CellFormat.Width = 0.4 * 72; //0.4"

builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;

Borders borders = builder.CellFormat.Borders;

borders.LineStyle = LineStyle.Single;

borders.LineWidth = 2;

borders.Color = System.Drawing.Color.Blue;

for (int y = 0; y < 8; y++)

{

for (int x = 0; x < 8; x++)

{

builder.InsertCell();

builder.Write(string.Format("X{0}, Y{1}", x, y));

//This alternatives cell backgrounds.

bool isBlack = (((x + y) & 0x01) != 0);

builder.CellFormat.Shading.BackgroundPatternColor =

(isBlack) ? System.Drawing.Color.LightGreen : System.Drawing.Color.LightYellow;

}

builder.EndRow();

}

builder.EndTable();

How can I avoid this behavior and have the table always in the correct position?

Thank you,

Andra

Hi

Thanks for your request. I think that problem occurs because the table in the template file has text wrapping = “Around”. Try to set text wrapping = “None” and this will solve your problem. (Table Properties / Table / Text Wrapping = “None”). Also see attachment. There is the modified template file.

Best regards.

You are right. Thank you very much for your quick answer.

Have a nice Day!