How to split table with largne number of columns in Table

I am using Aspose.Words for .Net.
I have created a table using AsposeTableBuilder and DocumentBuilder.
Table columns are dynamic(based on data). So, if data are more than either columns are too shrink or columns are expanded to out of the page and hence, some columns are not visible.
So, I want to split/break/wrap the table (whenever there is a large number of columns to be displayed) by column. This is possible in PDF but don’t know about word.
So, can anyone please help me in achieve this.

Hi Rakesh,

Thanks for your inquiry. Well, a table with too many columns wouldn’t be properly visible in a normal word document because there are so many columns. Could you clarify exactly how your report looks like when generated? Please also attach your target Word document as to how you want your desired results be generated like (please create this document by using Microsoft Word). You can most likely work around this issue by creating a second table when your input data reaches beyond the visible area of Page and place the remaining data into the second table instead. Then you can place these tables one after others.

Best regards,

Hi Awais,
Thanks for your reply.
I have attached sample document to show you what is the current output and what is desired output.
Actually I want to know is there any property (may be table property) available in Word to wrap columns (columns goes off the page) to next page or paragraph or something like that?

Hi Rakesh,

Thanks for the additional information. We are checking with this scenario and will get back to you soon.

Best regards,

Hi Rakesh,

Thanks for being patient. You can adopt the following code to be able to manually split big rows into two rows and achieve your desired output.

// Load document
Document doc = new Document(@"C:\Temp\Sample+Document.docx");
// Get reference to page setup instance
PageSetup ps = doc.FirstSection.PageSetup;
// Get reference to the table you want to work on
Table tab = doc.FirstSection.Body.Tables[0];
// Create a duplicate of this table
Table workingTab = (Table) tab.Clone(true);
// Remove all rows from the cloned table
workingTab.Rows.Clear();
// Create a LayoutCollector instance
LayoutCollector collector = new LayoutCollector(doc);
// Create a LayoutEnumerator instance
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
// Determine if the first row is displayed beyond the right page bounds
enumerator.Current = collector.GetEntity(tab.FirstRow.LastCell.FirstParagraph);
while (enumerator.MoveParent())
    if (enumerator.Type.Equals(LayoutEntityType.Row))
        break;
// Get the width of Row
float rowWidth = enumerator.Rectangle.Width;
if (rowWidth > ps.PageWidth - ps.LeftMargin)
{
    // First row is our header row, split it into two rows
    List < Row > headerRows = SplitRowIntoTwo(tab.FirstRow, 11);
    Row headerRow1 = headerRows[0];
    // We will repeat the following header row after the completeion of every record in datasource
    Row headerRow2 = headerRows[1];
    // Add the first part of the header row to the new table
    workingTab.Rows.Add(headerRow1);
    for (int i = 1; i < tab.Rows.Count; i++)
    {
        // Split each row in main table into two rows
        List < Row > rows = SplitRowIntoTwo(tab.Rows[i], 11);
        // Add first part of the row to the working table
        workingTab.Rows.Add(rows[0]);
        // add the separator header row
        workingTab.Rows.Add(headerRow2.Clone(true));
        // Add remaining part of the row to the working table
        workingTab.Rows.Add(rows[1]);
        // Repeat this process for every row in main table
    }
}
// Add the final table to Body
doc.FirstSection.Body.Tables.Add(workingTab);
// Apply someformatting
workingTab.Style = tab.Style;
workingTab.PreferredWidth = PreferredWidth.FromPercent(108.6);
// Save document
doc.Save(@"C:\Temp\out.docx");

public static List < Row > SplitRowIntoTwo(Row row, int cellIndex)
{
    List < Row > rows = new List < Row > ();
    List < Cell > cells = new List < Cell > ();
    for (int i = 0; i < cellIndex; i++)
        cells.Add(row.Cells[i]);
    Row tempRow = new Row(row.Document);
    foreach(Cell cell in cells)
    tempRow.Cells.Add(cell.Clone(true));
    rows.Add(tempRow);
    cells.Clear();
    cells.Add(new Cell(row.Document));
    for (int j = cellIndex; j < row.Cells.Count; j++)
        cells.Add(row.Cells[j]);
    tempRow = new Row(row.Document);
    foreach(Cell cell in cells)
    tempRow.Cells.Add(cell.Clone(true));
    rows.Add(tempRow);
    return rows;
}

I hope, this helps.

Moreover, I have attached an output document here for your reference.

Best regards,