Table Creation ... Breaking changes

I’ve had routines to create tables that have worked … they are now breaking in the following areas.

bldr.RowFormat.AllowAutoFit = False

I replaced this code with (after the table was created):

Table.AllowAutoFit = false

This generates an error as there are no rows in the table at this time.
In the past, I built a table a cell at a time and applied formatting to the cell. This is now breaking indicating there are no rows in the table.
Are there some new ways to make tables? Recommended ways to work with tables? I use the ‘builder’ for all major tasks … like creating tables.
Any pointers appreciated to know best practice for tables in 10.5.
Regards, Bruce

oops … I just removed the line entirely and all is back to normal.
I haven’t really looked at tables for a while … I would still appreciate any new tricks and tips with tables … for example, table styles (if related to word table styles in documents).
Any pointers appreciated!!
Regards, Bruce

Hi Bruce,

You can create a sample word table with one column and one row by using the following code:

// Initialize Document Document objDocument = new Document();

// Create DocumentBuilder so we can modify the document.
DocumentBuilder objDocumentBuilder = new DocumentBuilder(objDocument);
// Insert table using document builder
objDocumentBuilder.CellFormat.Width = 10;
objDocumentBuilder.CellFormat.Borders.LineWidth = 0.8;

objDocumentBuilder.Bold = false;
objDocumentBuilder.Write("Row Value");
// End table
Aspose.Words.Tables.Table objTable = objDocumentBuilder.EndTable();

You can look at following links for your reference, where you can find DocumentBuilder properties, methods, and their sample code.

Imran Rafique

Hi Bruce,

Thanks for your inquiry.

Yes there were a few changes to the Tables API in the latest version. We will have full documentation of this online within a week or so.

In the mean time please feel free to take a look at the examples in the API:


Thanks for the pointers … I gave the preferredwidth property a try with a two column table with widths of 25% and 75%. (I just replaced setting the width with the preferredwidth).
The table did not span the entire width of the page (A4) only about 4cm with 2cm = width for each column. I currently do all of the calculations so it works when I set the width of each cell … however, I have a number of tables that are much more complicated where this would help.
I’ll wait to see your full documentation. I must be missing something.
Regards, Bruce

Hi Bruce,

Thanks for your inquiry.

Could you post some simple code which demonstrates the issue you are having? We will then provide you with some further feedback.


I’ve zipped a routine that generates a type of table. I’ve highlighted 3 sections in the routine where I’ve had problems:

  1. Removed code .AllowAutoFit = False
    The code caused a fault (most likely no cell added to the table at this point)

  2. 2 instances of setting ‘Aspose.Words.Tables.PreferredWidth.FromPercent(25)’

(the other is 75 percent)
I am expecting (once I understand them) that the table styles will clean up a lot of the code currently in the routine.
the second problem results in two columns not using the full width of the page and only about 4 cm wide. I’m sure I’m missing some code to make it work.
Thanks in advance for taking a look at the routine.
Regards, Bruce

Hi Bruce,

Thanks for this additional information.

I’m afraid however your code is too deeply nested with your own business code and I’m unable to get it to run.

Could you please create a simple example which demonstrates the issue you are having?


Another sample same code with calling parameters removed. I have also attached 4 PDF files with results of using the routine.
Normal = normal output from the application
withPrefered width (25 / 75)
with AllowAutoFit = false
With AllowAutoFit = true
For some reason, the table is not using the full width.
Hope this helps… If not, I’ll use your new documentation and then submit again.
Regards, Bruce

Hi Bruce,

Thanks for your inquiry.

It appears that the current behaviour is correct, if you create a similar table in MS Word then you get the same sort of thing (a table which is proportionally correct but only takes up half the page width).

To set the table to take up the full page width you should apply table preferred width as well, please see the code below.

pclrCellBack = Color.LightYellow
.CellFormat.WrapText = True
ptblUse.AllowAutoFit = True
ptblUse.PreferredWidth = PreferredWidth.FromPercent(100)

If there is anything else we can help you with, please feel free to ask.


Thanks for taking a look at the sample. I thought there must be something I was missing. Pretty obvious now that I think about it.
Many thanks, Regards, Bruce

Hi Bruce,

It’s great things are working as expected again. Please feel free to ask if you have any further issues.

Also, it shouldn’t be necessary to explicitly set the table preferred width when you are setting a cell preferred width to percent. In a more simple table the table preferred width is automatically applied as soon as you set the cell preferred width in this way. However in your code this doesn’t seem to happen.

I took a closer look into this and this seems to occur because of the call to RowFormat.ClearFormatting() at the start of the method. I have logged this issue as a bug. We will keep you informed of any developments.


The issues you have found earlier (filed as WORDSNET-5327) have been fixed in this Aspose.Words for .NET 18.8 update and this Aspose.Words for Java 18.8 update.