@sukesh.kotian
Thanks for your feedback. Yes, your finding is correct you are getting issue due to page size limitation of MS Word. You can reduce cell size, AutoFitBehavior and set page size to 22 inches to accommodate your table in 22 inches page width. Please check following sample code for reference.
Furthermore, please note by default Document page size is letter so please call document header creation code after table creation to fit it to updated page size.
static void createTable(DocumentBuilder builder) throws Exception {
com.aspose.words.Table table = builder.startTable();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().setWidth(37);
Color color = new Color(255, 200, 158);
String[] columns = {"Employee Full Name", "Assignment Number", "Employee Number", "Employment Category", "Date Of Hire", "Gender", "Assignment Status", "Date Of Birth", "Job Name", "Position Name", "Marital Status", "Supervisor Full Name", "Payroll Name", "Grade Name", "Social Security Number", "Location Name", "Government Reporting Entity", "Organization Name", "Pay Basis", "Person Type", "Adjusted Service Date", "Latest Hire Date", "Address Line1", "Address City", "Address County", "Address State", "Address Zip", "Length Of Service", "Annual Salary", "Ledger", "Currency Name", "Default Expense Account", "Spinal Point", "Ceiling Point", "Grade Step", "Placement Eff Date", "Bargaining Unit", "Collective Agreement Name", "Revised Sal"};
for (String column : columns) {
builder.insertCell();
builder.getFont().setBold(true);
builder.getFont().setSize(12);
builder.getCellFormat().getShading().setBackgroundPatternColor(color);
builder.write(column);
}
builder.endRow();
table.setLeftPadding(3);
table.setRightPadding(3);
table.setTopPadding(3);
table.setBottomPadding(3);
table.setBorders(LineStyle.SINGLE, 0.5, Color.gray);
table.setAllowAutoFit(true);
//table.autoFit(AutoFitBehavior.AUTO_FIT_TO_CONTENTS);
table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
// builder.getCurrentSection().getPageSetup().setPageWidth(PreferredWidthType.AUTO);
builder.getCurrentSection().getPageSetup().setPageWidth(22*72);
builder.endTable();
}
public static void test() throws Throwable, Exception {
com.aspose.words.Document doc = new com.aspose.words.Document();
DocumentBuilder builder = new DocumentBuilder(doc);
createTable(builder);
createDocumentHeader(builder);
doc.updateFields();
doc.updateTableLayout();
doc.save("D:\\Downloads\\GenerateRTF\\test.rtf", com.aspose.words.SaveFormat.RTF);
}