Problem resizing tables

Hello,

I am trying to use Aspose.Words to insert some html to a Word file with content already in it. I am having a problem resizing some tables that were inserted. After the html that contains tables has been inserted I use a form of the method described here: https://forum.aspose.com/t/63619
to attempt to resize the table to fit the page. However, nothing I do seems to have any effect on the width of the cells. Here is the method I’m using:

private static void fitTableToPageWidth(Document doc) throws Exception
{

    NodeCollection nc = doc.getChildNodes(NodeType.TABLE, true, false);

    for (Node n: nc)
    {
        Table table = (Table) n;
        Section section = (Section) table.getAncestor(NodeType.SECTION);
        Table pTable = (Table) table.getAncestor(NodeType.TABLE);
        if (pTable != null)
        {
            return;
        }
        double pageWidth = section.getPageSetup().getPageWidth() - (section.getPageSetup().getLeftMargin() + section.getPageSetup().getRightMargin());
        double tableWidth = 0;
        for (com.aspose.words.Row row: table.getRows())
        {
            row.getRowFormat().setAllowAutoFit(true);
            double rowWidth = 0;
            for (com.aspose.words.Cell cell: row.getCells())
            {
                rowWidth += cell.getCellFormat().getWidth();
                cell.getCellFormat().setFitText(true);
            }
            if (rowWidth> tableWidth)
                tableWidth = rowWidth;
        }
        for (com.aspose.words.Row row: table.getRows())
        {
            for (com.aspose.words.Cell cell: row.getCells())
            {
                double cellRatio = cell.getCellFormat().getWidth() / tableWidth;
                double cellWidth = cellRatio * pageWidth;
                cell.getCellFormat().setWidth(cellWidth);
            }
        }
    }
}

and here is where I call it:

for (MyItem item: items)
{
    db.writeln(item.getName());
    db.insertHtml(item.getHTMLString());
    db.writeln();
}

fitTableToPageWidth(doc);

This outputs each of our items with name and then an html field. After all items have been written I go back and attempt to resize any tables. I know through debug walkthroughs that the method is finding the tables correctly and appears to work correctly calculating and setting the appropriate cell sizes, but the resulting file has had no table size changes whatsoever. Do you have any ideas why this might be and how I might be able to get it working? Thank you.

Hi

Thanks for your inquiry. Could you please provide sample HTML here for testing? I will check it and provide you more information.
The problem might occur because width of whole table is set in your HTML. If you have control over your HTML. You can try avoiding setting width of whole table. This could help to resolve the problem.
Best regards,

The problem was with having a table width set, thank you. I managed to use a regex to remove the width attribute.