That would work if I was alsways going to process the exact same text. However, I provided the example string and code as a method to easily replicate the issue. The string will not be static and may or may not contain , or tags at any location within the text. The current full function looks like:
private void write_Annotation(String sAnnotation, Int32 iStartRow, Int32 iColumn, Aspose.Cells.TextAlignmentType aAlign)
{
String[] sLines;
Int32 iCurrentRow;
String sCleanedLine;
Aspose.Cells.Cell aCell;
Int32 iStart;
Int32 iEnd;
String sTargetFragment;
String sPreFragment;
string[] sTagArray = { "b", "u", "i" };
if (sAnnotation.Length > 0)
{
sLines = sAnnotation.Split('\n');
iCurrentRow = iStartRow;
foreach (String sLine in sLines)
{
sCleanedLine = Strip_Html(sLine);
aCell = Worksheet.Cells[iCurrentRow, iColumn];
aCell.PutValue(sCleanedLine);
aCell.Style.Font.Size = 8;
aCell.Style.HorizontalAlignment = aAlign;
foreach (String sTag in sTagArray)
{
Int32 iStartIndex = 0;
while (sLine.IndexOf("<" + sTag + ">", iStartIndex, StringComparison.CurrentCultureIgnoreCase) != -1)
{
iStart = sLine.IndexOf("<" + sTag + ">", iStartIndex, StringComparison.CurrentCultureIgnoreCase);
iEnd = sLine.IndexOf("", iStart + 1, StringComparison.CurrentCultureIgnoreCase);
sTargetFragment = Strip_Html(sLine.Substring(iStart, iEnd - iStart + 4));
if (iStart > 0)
{
sPreFragment = Strip_Html(sLine.Substring(0, iStart));
}
else
{
sPreFragment = "";
}
switch (sTag)
{
case "b":
aCell.Characters(sPreFragment.Length, sTargetFragment.Length).Font.IsBold = true;
break;
case "u":
aCell.Characters(sPreFragment.Length, sTargetFragment.Length).Font.Underline = Aspose.Cells.FontUnderlineType.Single;
break;
case "i":
aCell.Characters(sPreFragment.Length, sTargetFragment.Length).Font.IsItalic = true;
break;
}
iStartIndex = iStart + 1;
}
}
iCurrentRow++;
}
}
}
What you can see here is that we pass a string into the function that may contain HTML code. We strip the HTML and load the cleaned text into the cell. Finally we look at the original string to identify characters that should have formatting applied.