We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to fix this table coloumn for large data?

Hi, i want to adjust this table column without increasing its width for larger data? How can i achieve this?
Note: I am not increase its width programmatically, table auto adjust this column width.
See below image to understand my problem easily.
comments_column_issue.jpg (94.4 KB)

@affan1996 Could you please attach your input and expected output documents here for testing? We will check the documents and provide you more information.
Also, please try using Table.AutoFit method and let us know if this is what you are looking for.

See the comments column on page number 3 of these documents.
report_expected.docx (18.6 KB)
report_actual.docx (18.6 KB)

@affan1996 Thank you for additional information. In your table there is a cell with very long value (link) that is why auto fit will not work as expected. In your case you should specify fixed cell width to get the desired output.
Also, it looks like the tables in your document were inserted from HTML. If so, you can adjust the table in the source HTML to get the desired output. If I am right, please attach the source HTML here for our reference.

can you guide me how to define cell width in this case and can i have to AutoFit to fixed column width before assigning fixed cell width?

@affan1996 The problem with this table is that it is nested into another table. In nested table allow auto fit is always on. So to get the desired output you should move the table outside the root table. For example see the following code:

Document doc = new Document(@"C:\Temp\in.docx");

// The problematic table is nested into the third table.
Table parentTable = doc.FirstSection.Body.Tables[2];

// Get the second nested table.
Table t = (Table)parentTable.GetChild(NodeType.Table, 1, true);

// Put table into the main content, since nested table has AllowAutoFit always enabled in MS Word.
Paragraph delimiter = new Paragraph(doc);
parentTable.ParentNode.InsertAfter(delimiter, parentTable);
parentTable.ParentNode.InsertAfter(t, delimiter);

// Calculate width of table and each column.
PageSetup ps = doc.FirstSection.PageSetup;
double tableWidth = ps.PageWidth - ps.LeftMargin - ps.RightMargin;
double colWidth = tableWidth / t.LastRow.Cells.Count;

t.FirstRow.FirstCell.CellFormat.Width = tableWidth;
// Specify width of cells in the thatble except the first row.
for (int i = 1; i < t.Rows.Count; i++)
{
    Row r = t.Rows[i];
    foreach (Cell c in r.Cells)
        c.CellFormat.Width = colWidth;
}

t.AllowAutoFit = false;
t.AutoFit(AutoFitBehavior.FixedColumnWidths);

doc.Save(@"C:\Temp\out.docx");

Here is output document produced by this code: out.docx (18.6 KB)

Ok thanks i try this. I think its create performance issue if i have large number for data or lets assume i have 10,000 tables in document.

@affan1996 Unfortunately, there is no other way. Even in MS Word you cannot correct the column widths if the table is nested into another table.