Resize Table Cells in Word using Java

Hi,

In my requirement, i am creating a document in which contains a table. In table some rows are merged.

My issue is that rows after the merge is not coming proper align with the header. How to Resize Table Cells in Word to avoid this issue?

attaching the outputoutput.docx (7.5 KB). and the sample code wrdHtmlWithReplacePoc.zip (13.5 KB). This is my expected output expected_output.docx (11.8 KB).

Please give a solution for the problem

@Gptrnt

In your case, we suggest you please use Table.autoFit method as shown below to get the desired output. We have attached the output DOCX with this post for your kind reference.
output.docx (7.4 KB)

Code to Resize Table Cells in Word

private static void CreateTable(DocumentBuilder builder) throws Exception {
    Table table = builder.startTable();
    insertRow(builder);
    insertMergeRow("Test1", builder);
    for (int i = 0; i < 3; i++){
        insertRow(builder);
    }
    insertMergeRow("II. Test2", builder);
    for (int i = 0; i < 3; i++) {
        insertRow(builder);
    }
    insertMergeRow("III. Test3", builder);
    for (int i = 0; i < 3; i++){
        insertRow(builder);
    }
    builder.endTable();
    table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW);
}

Hi Tahir,

Thanks for your solution. It’s working good.