I am also facing the same issue in aspose word where url is not getting wrapped. Tried with AutoFitTowindow, AutoFitToContent with allow autofit to false as well as true though url column is getting wrapped it is impacting other columns as in below screenshot
Please provide a solution for this issue
Here is snippet of code.
Document doc = new Document();
int counter = 0;
Table table = new Table(doc);
doc.FirstSection.Body.AppendChild(table);
Row rowHeader = GetNewRow(doc);
table.AppendChild(rowHeader);
Style style = GetTableRowHeaderStyle(doc);
style.Font.Size = 8;
Style styleRow = GetTableRowStyle(doc);
styleRow.Font.Size = 8;
string[] headers = new string[] { "ID", "Name", "Value", "Language" };
int[] cellWidths = new int[] { 300, 150, 400, 150 };
BuildRowHeader(doc, rowHeader, headers, style, cellWidths);
foreach (var languagesepecific in alllanguagelinklibrarydetails)
{
languagesepecific.Value.ForEach((linklib) =>
{
counter++;
Row row = GetNewRow(doc);
table.AppendChild(row);
Color cellColor = Color.FromArgb(221, 219, 213);
if (counter % 2 != 0)
{
cellColor = Color.White;
}
doc = BuildTableCell(doc, row, Convert.ToString(linklib.code), cellColor, 0, styleRow, false);
doc = BuildTableCell(doc, row, linklib.name, cellColor, 0, styleRow, false);
doc = BuildTableCell(doc, row, linklib.value, cellColor, 0, styleRow, false);
doc = BuildTableCell(doc, row, languagesepecific.Key, cellColor, 0, styleRow, false);
});
}
table.AutoFit(AutoFitBehavior.AutoFitToWindow);
table.SetBorders(LineStyle.Single, 1.0, Color.Gray);
indent preformatted text by 4 spaces
private static Document BuildTableCell(Document doc, Row tableRow, string cellText, Color cellBgColor, int borderWPreformattedtextidth, Style cellStyle, bool wrapText = false, double cellWidth = 0)
{
var cell = new Cell(doc);
cell.CellFormat.Shading.BackgroundPatternColor = cellBgColor;
cell.CellFormat.Borders.LineWidth = borderWidth;
cell.CellFormat.WrapText = wrapText;
cell.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
cell.CellFormat.LeftPadding = 5;
if (cellWidth != 0)
cell.CellFormat.Width = cellWidth;
tableRow.AppendChild(cell);
var para = new Paragraph(doc);
para.ParagraphFormat.Style = cellStyle;
tableRow.LastCell.AppendChild(para);
var htmlDocument = new HtmlAgilityPack.HtmlDocument();
htmlDocument.LoadHtml(cellText);
tableRow.LastCell.FirstParagraph.AppendChild(new Run(doc, htmlDocument.DocumentNode.InnerText));
return doc;
}
}
table.png (10.1 KB)