ONLY FORMAT font-forecolor, strong, Italics, Bold, Underline
Call this method by giving reference of Cell and HTML content.Also, attach TextFormatter.cs along with this function to your project.
private void PopulateDocumentCell(ref Aspose.Cells.Cell objCell, string HTMLTEXT)
{
try
{
//Defining Default Properties as ISBOLD^ISITALICS^ISUNDERLINE^FORECOLOR^BGCOLOR
DataTable dtStringInfo = TextFormatter.PopulateDataTableOfTagInfo(HTMLTEXT);
//Read the DataTable and populate the cell.
if (dtStringInfo.Rows.Count > 0)
{
//Populate String.
string strCellContent = string.Empty;
foreach (DataRow dr in dtStringInfo.Rows)
{
strCellContent += dr["Text"];
}
objCell.PutValue((string) strCellContent);
//Now format the text.
int intStartPosition = 0;
foreach (DataRow dr in dtStringInfo.Rows)
{
if ((dr["Bold"].ToString() == "1"))
{
objCell.Characters(intStartPosition, dr["Text"].ToString().Length).Font.IsBold = true;
}
if ((dr["Italics"].ToString() == "1"))
{
objCell.Characters(intStartPosition, dr["Text"].ToString().Length).Font.IsItalic = true;
}
if (dr["UnderLine"].ToString() == "1")
{
objCell.Characters(intStartPosition, dr["Text"].ToString().Length).Font.Underline = FontUnderlineType.Single;
}
if(dr["ForeColor"].ToString()!="#000000")
{
objCell.Characters(intStartPosition, dr["Text"].ToString().Length).Font.Color =
TextFormatter.HexStringToColor(dr["ForeColor"].ToString());
}
intStartPosition += dr["Text"].ToString().Length;
}
}
objCell.Style.VerticalAlignment = TextAlignmentType.Top;
objCell.Style.IsTextWrapped = true;
}
catch (Exception)
{
string strValue = TextFormatter.GetPlainText(HTMLTEXT);
while (strValue.Length > 2)
{
if (strValue.Substring(0, 1) == "\n")
{
strValue = strValue.Substring(1, strValue.Length - 1);
}
else
{
break;
}
}
objCell.PutValue((string) strValue);
objCell.Style.VerticalAlignment = TextAlignmentType.Top;
objCell.Style.IsTextWrapped = true;
}
}