Hello Team,
Aspose.Word Version : 22.11
I have added a code in backend that gives the cells width evenly based on the table width, but when I export the DOCX, the result is the column with more content gets the maximum width.
Refer following code:
width = 510.5 / cell.getParentRow().getCells().getCount();
table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
for (Cell cell1 : (Iterable<Cell>)table.getChildNodes(NodeType.CELL, true))
{
CellFormat cellFormat = cell1.getCellFormat();
cellFormat.setWidth(width);
cellFormat.setPreferredWidth(PreferredWidth.fromPoints(width));
}
@kalpeshAspose1997 Sorry I cannot reproduce your issue on my end, Iām using the latest version of Aspose.Words (23.4) and the following code:
Table table = (Table)doc.getChildNodes(NodeType.TABLE, true).get(0);
if(table != null)
{
table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
table.setAllowAutoFit(false);
for (Row row : (Iterable<Row>)table.getRows())
{
double width = 510.5 / row.getCells().getCount();
for (Cell cell1 : (Iterable<Cell>)row.getCells())
{
cell1.getCellFormat().setWidth(width);
cell1.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(width));
}
}
}
doc.save("C:\\Temp\\outputFixedWidth.docx", SaveFormat.DOCX);
outputFixedWidth.docx (8.2 KB)
1 Like