Free Support Forum - aspose.com

Nested table is not retaining its width when table has fixed column width

Hello,


we are building table(main) in word with FIXED_COLUMN_WIDTHS, and in one of the row we are adding another table(nested table), by doing this the nested table is adding in the first column of the main table, not the entire row. the nested table column is having its own width.

if the main table is of auto fit, then it is working as expected.
attached the screenshots, could you please help me what causing the issue.

Technical details:

Table table = new Table(this.doc);
table.setAllowAutoFit(false); // by disabling autofit, table will consider column width only
table…autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS); // optional

Row row = new Row(this.doc);
– adding cells to the row–

table.appendChild(row);

then creating the nested table and adding to the main table

if (nestedTable != null)
{

Row tablContainerRow = new Row(this.doc);
table.appendChild(tablContainerRow);

// https://docs.aspose.com/display/wordsnet/Working+with+Merged+Cells
Cell firstCell = new Cell(this.doc);
firstCell.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
firstCell.appendChild(nestedTable );
tablContainerRow.appendChild(firstCell);

Cell secondCell = new Cell(this.doc);
secondCell.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
tablContainerRow.appendChild(secondCell);

Cell thirdCell = new Cell(this.doc);
thirdCell.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
tablContainerRow.appendChild(thirdCell);

Cell fourthCell = new Cell(this.doc);
fourthCell.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
tablContainerRow.appendChild(fourthCell);
}


Regards,
Ramesh

Hi Ramesh,


Thanks for your inquiry. We have tested the scenario with attached sample code using Aspose.Words for Java 17.4 and unable to notice the reported formatting issue. We will appreciate it if you please share your complete sample code to replicate the issue at our end, so we will further look into the issue and will guide you accordingly.

Best Regards,

Hi Tilal Ahmad,


Thanks for your quick reply,

we are using the Aspose Words for Java 15.8, is this issue is because of lower version?


Regards,
Ramesh


Hi Tilal Ahmad,



Thanks for the sample code with word type doc.

Both of our code found to be working fine for word “doc type(i.e Good:) ). But not working for “docx” and “rtf”.

and furthor when we have type “rtf” it is behaving same as “docx” for fixed column width which is still a issue and when we have auto the nested table is taking the width of the window not the parent table.


and in your example code you didnot gave the width for the nested table cell. line no 92
cell.getCellFormat().setWidth(80); —> cellnest1.getCellFormat().setWidth(80);


Note: I tested with Aspose Words for Java 15.8


Regards,
Ramesh

Hi Ramesh,


Thanks for your feedback. My shared example code gives same result for DOCX file regardless of AllowAutoFit property value. As requested above, please share your working code here, it will help us to replicate your issue exactly and address it accordingly.

Best Regards,

Hi Tilal Ahmad,


I have tested with your code as well and it does not worked for me either. I have added the code sample as well and aslo see the attached screenshot.



Regards,
Ramesh

Hi Ramesh,


Thanks for sharing your sample code. We have tested your sample code and noticed that it is Aspose.Words for Java 15.8 bug. However, it has been fixed in some later version. We are unable to notice the reported issue in Aspose.Words for Java 17.4. Please download and try latest version of Aspose.Words for Java, it will resolve the issue.

Furthermore, please note we maintain a single code base. All fixes and improvements are made in latest version of Aspose.Words. So it is always recommended to use latest version.

Best Regards,

Hi Tilal Ahmad,


Thanks for reply, we will test it with latest version. if still have issue, we will let you know.



Regards,
Ramesh