Help with Table Formatting in Word and breaking across pages

I am user a builder to create this document and there are a number of tables that i need to create.
I need to do 2 things that I’m currently having difficulty with.

  1. I need the rows to be the minimum height they can be while accommodating wrapped text (so using builder.getRowFormat().setHeight(15); ist workable).

  2. I need to prevent any page breaks from occurring in the table. i tried the below line, but it didnt seem to do what i thought it would.

builder.getRowFormat().setAllowBreakAcrossPages(false);

Hi there,
Thanks for your inquiry.
You can set the minimum height of a row by using the code below.

builder.RowFormat.HeightRule = HeightRule.AtLeast;
builder.RowFormat.Height = 15;

Regarding how to avoid tables splitting across the page, please try setting thethe ParagraphFormat.KeepWithNext property for each paragraph inside the table. This will cause the entire table to keep together across a page break.

builder.ParagraphFormat.KeepWithNext = true;
builder.StartTable();
builder.InsertCell();
builder.Writeln("Text");
builder.EndRow();
builder.EndTable();
builder.ParagraphFormat.KeepWithNext = false;

Thanks,

When i use the

builder.getRowFormat().setHeight(15);
builder.getRowFormat().setHeightRule(HeightRule.AT_LEAST);

i get:
http://s4.postimage.org/o3kqfp0wy/15auot.png

when i use

builder.getRowFormat().setHeight(15);
builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);

i get:
http://s4.postimage.org/o3ldl7vtu/15exact.png

I want the look of the later, but it doesn’t allow for wrapping.

Hello
Thank you for additional information. Could you please attach your input and expected output documents here for testing? I will check them and provide you more information.
Best regards,

It seems what you are asking for is “Auto-fit to Content” option in MS Word. Unfortunately, currently there is no way to set this option using Aspose.Words. We plan to support this in the one of future releases. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.
At the moment, you can only specify fixed width and height of each cell in the table.
Best regards,

Hi there,
Actually it looks like you are just looking for auto fitting the height on each row. This should happen automatically if you use HeightRule.Auto. As long as you set a size for the cell width the text will wrap around the line and the row height will auto fit itself to the text in the row. Please see the code below.

builder.StartTable();
builder.CellFormat.Width = 30;
builder.RowFormat.HeightRule = HeightRule.Auto;
builder.InsertCell();
builder.Write("Some Text");
builder.InsertCell();
builder.Write("Some Text");
builder.InsertCell();
builder.Write("More Text");
builder.EndRow();
builder.InsertCell();
builder.Write("Some Text");
builder.InsertCell();
builder.Write("Some Text");
builder.InsertCell();
builder.Write("More Text");

Thanks,

Hi,
Do you still have the problem with the table?

I am unlinking this thread from the “auto-fit” issue because it is not quite about that.

Let us know if you still need help.