We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose 11.2 - table preferred with defaults to 100%

Hey support,

with Aspose 11.2 the table default width defaults to “100%” which results in the table resizing to fit the page which is not the expected behavior. Setting explicitly the preferred width to AUTO seems to be working but that was not necessary with previous builds.

Regards,
Dragos

Hi Dragos,

Thanks for your inquiry.

I believe ever since the introduction of the new tables API in Aspose.Words 10.5 all tables are inserted by default with 100% table width. I don’t see any indication of this having changed in the latest version.

Could you please post a quick example that you are using here for testing?

Thanks,

Hey Adam,

with Aspose 10.5 and 11.0 the tables do not have the preferred width set to 100% by default. Code and output for 10.5 and 11.2 attached. The change seems to have occurred in the clearFormatting method for rows.

@Test
public void testSimpleTable() throws Exception
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    builder.getRowFormat().clearFormatting();

    Table table = builder.startTable();

    builder.insertCell();
    builder.write("Table preferred width: " + table.getPreferredWidth());

    // This cell is merged to the previous and should be empty.
    builder.insertCell();
    builder.write("Lore ipsum");
    builder.endRow();

    builder.endTable();

    doc.save("d:\tmp\testSimple.doc");
    doc.save("d:\tmp\testSimple.pdf");
}

Regards,
Dragos

Hi Dragos,

Thanks for your inquiry. No, I don’t think that this behaviour is caused by getRowFormat().clearFormatting() method (try commenting/un-commenting this line). In newer versions, by default a table is inserted at 100% width. May be you can use the following line of code to achieve what what you’re looking for:



builder.endTable();
table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);

Best Regards,

Hey Awais,

I did not try the code but even if that works it was not needed in 11.0/10.5. The issue here is not the change in itself but the lack of documentation on the change.

Regards,
Dragos

Hi Dragos,

Thanks for your inquiry. We will be sure to improve this part of our API documentation. Sorry for the inconvenience.

Best Regards,