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);
}
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.