Hi Andrea,
Thanks for sharing the details. Please use the ToString method with SaveFormat.Text parameter as shown below instead of GetText method.
((Run)nodetowrite).Text = tab.Rows[row].Cells[cell].ToString(SaveFormat.Text);
Please replace the following line of code with above line in your code.
((Run)nodetowrite).Text = tab.Rows[row].Cells[cell].GetText();
Moreover, You may also use the DocumentBase.ImportNode method to imports a nodes from another document to the current document. Importing a node creates a copy of the source node belonging to the importing document. The returned node has no parent. The source node is not altered or removed from the original document.
Please see the code below, hope this helps you.
//open the docx template
Document ReportDoc = new Document(MyDir + "template.docx");
//open a sample docx containing the data (the data usually comes from another source)
Document DataDoc = new Document(MyDir + "data.docx");
//populate the table...
ReportDoc.JoinRunsWithSameFormatting();
Table table = (Table)ReportDoc.FirstSection.Body.GetChild(NodeType.Table, 0, true);
Table table2 = DataDoc.FirstSection.Body.GetChild(NodeType.Table, 0, true) as Aspose.Words.Tables.Table;
foreach (Row row in table2.Rows)
{
Node dstRow = ReportDoc.ImportNode(row, true, ImportFormatMode.KeepSourceFormatting);
table.Rows.Add(dstRow);
}
//save the output docx
ReportDoc.Save(MyDir + "output.docx");
//save the output pdf
ReportDoc.Save(MyDir + "wrong_output.pdf");
Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.