I am using a Word Doc Template which contains a Table with Bookmarks. Populating the bookmarks is not the issue. At the end of the table I am inserting a varying number of rows retrieved from the database. My approach is to CLONE the last row, clear the existing data for each cell, populate each cell, append row, and repeat the process for the next database row.
The issue I am trying to solve is the data put into the cell will contain HTML tags and I am trying to format the table cell to display as HTML. My code looks like this:
//------------------------------//
//------- Fields 09 to 12 ------//
//------------------------------//
Aspose.Words.Tables.Table FPVTable = (Aspose.Words.Tables.Table)ESHDoc.GetChild(NodeType.Table, 0, true);
cmd = DBUtility.CreateCommand();
cmd.CommandText = "Usp_GetReportData";
cmd.Parameters.Add(new SqlParameter("@Site_Id", ddlSite.SelectedItem.Value));
cmd.Parameters.Add(new SqlParameter("@YearVal", ddlPVYear.SelectedItem.Value));
cmd.Parameters.Add(new SqlParameter("@FA_Id", ddlFacilityArea.SelectedItem.Value));
dt = DBUtility.ExecuteCommand(cmd);
if (dt.Rows.Count > 0)
{
int CellCnt = 0;
foreach (DataRow dr in dt.Rows)
{
CellCnt = 0;
Aspose.Words.Tables.Row clonedRow = (Aspose.Words.Tables.Row)FPVTable.LastRow.Clone(true);
foreach (Aspose.Words.Tables.Cell myCell in clonedRow.Cells)
{
myCell.RemoveAllChildren();
myCell.EnsureMinimum();
if (CellCnt == 0)
{
//--- Information contains HTML tags
myCell.FirstParagraph.Runs.Add(new Run(ESHDoc, dr["Column9"].ToString().Replace("<","<").Replace(">", ">")));
}
if (CellCnt == 1)
{
myCell.FirstParagraph.Runs.Add(new Run(ESHDoc, dr["FSD"].ToString()));
myCell.FirstParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;
}
if (CellCnt == 2)
{
myCell.FirstParagraph.Runs.Add(new Run(ESHDoc, dr["RAC"].ToString()));
myCell.FirstParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;
}
if (CellCnt == 3)
{
//--- Information contains HTML tags ("<" & ">")
myCell.FirstParagraph.Runs.Add(new Run(ESHDoc, dr["CAR"].ToString()));
}
myCell.FirstParagraph.Runs[0].Font.Size = 8;
myCell.FirstParagraph.Runs[0].Font.Name = "Calibri";
CellCnt++;
}
FPVTable.AppendChild(clonedRow);
}
}
What formatting call am I missing or should I be taking a different approach?