Trying to add HTML table to aspose word, and the column widths are expected to be fixed. But when text is too long, column width is changing.
Output with normal text:
Output when text length > column width
Code:
public Stream AddTableIntoWordFile()
{
String tableString = @"<style>
table{
border: 1px solid black;
table-layout: fixed;
width: 400px;
}
th, td {
border: 1px solid black;
overflow: hidden;
width: 200px;
}
</style>
<table>
<tbody>
<tr>
<td> Yours sincerely <br> For and on behalf of Test Limited</td>
<td>???????? ?????????????????????????????????????????????????????????????????????????????</td>
</tr>
</tbody>
</table>
";
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(tableString);
Table outerTable = (Table)doc.GetChild(NodeType.Table, 0, true);
outerTable.AutoFit(AutoFitBehavior.FixedColumnWidths);
doc.Save("result.docx");
var responseStream = new MemoryStream();
doc.Save(responseStream, SaveFormat.Docx);
responseStream.Seek(0, SeekOrigin.Begin);
return responseStream;
}
Appreciate your help.