Tables with DocumentBuilder

Hello,

I am evaluating ASPOSE word. I am trying to build tables dynamically using DocumentBuilder.

This is what I want to accomplish. I want to create a table with only the first cell in each row with a width of 75 pixels. And the rest of the cells in the row should be equal and the table should fill the whole page.

This is my code. This will make all the cells width 75 pixels.After we set the width in a table cell can we clear the width property?

builder.StartTable();

builder.Font.ClearFormatting();

builder.Font.Size = 12;

builder.InsertCell();

builder.ParagraphFormat.ClearFormatting();

builder.CellFormat.Width = WordConvert.PixelToPoint(75);

builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;

builder.write("1st Cell");

builder.InsertCell();

builder.write("2nd cell");

builder.InsertCell();

builder.write("3rd cell");

builder.Endrow();

builder.EndTable();

Thanks

maximus

Try the following approach. I cannot guarantee it will always work, but most of the time it will.

builder.StartTable();

Cell firstCellInARow;

builder.RowFormat.AllowAutoFit = false;

builder.Font.ClearFormatting();

builder.Font.Size = 12;

builder.InsertCell();

firstCellInARow = (Cell)builder.CurrentParagraph.ParentNode;

// intentionally setting cell width too big to allow Word autofit to do adjustment

builder.CellFormat.Width = WordConvert.PixelToPoint(1000);

builder.ParagraphFormat.ClearFormatting();

builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;

builder.Write("1st Cell");

builder.InsertCell();

builder.Write("2nd cell");

builder.InsertCell();

builder.Write("3rd cell");

builder.EndRow();

// set the desirable first cell width explicitly

firstCellInARow.CellFormat.Width = WordConvert.PixelToPoint(75);

builder.EndTable();

Otherwise, you need to set Autofit property to false, and set all cell widths explicitly. For this you need to know the width of the page text area and make all necessary calculations yourself.

Hello,

I tried the first option you gave me but it did not work. But explicitly setting the cell width based on the page size worked for me.

I just thought I will update this so that it will be helpful to others looking for a similar requirement.

Thanks ... maximus_vj