I’m using a dll named “Infragistics4.Documents.Excel.v15.1.dll” which was downloaded with Nuget. EDIT: The Nuget package manager in Visual Studio shows “Infragistics.Web.Documents.Excel” version 23.2.19.
I would like to create a cell that contains text with one letter a different color. How is this done?
A page at https://www.infragistics.com/help/wpf/excelengine-format-a-cell says that this should be possible with a FormatString.
I have tried setting the color in a format string:
myWorkSheet.Rows[iRowCount].Cells[3].CellFormat.FormatString = “#[red]#[blue]#########”;
I made a little progress by using:
myWorkSheet.Rows[iRowCount].Cells[3].CellFormat.FormatOptions = WorksheetCellFormatOptions.ApplyFontFormatting;
myWorkSheet.Rows[iRowCount].Cells[3].CellFormat.FormatString = “[red]”;
This colors the whole text red. I am looking to color individual characters.
1
Here is how to color an individual letter:
// set the cell's value to a FormattedString
FormattedString formattedString = new FormattedString(stringToDisplay);
worksheet.Rows[rowCount].Cells[colCount].Value = formattedString;
// get the index into the string of the character to highlight
int index = stringToDisplay.IndexOf(characterToHighlight);
// make that one character red and boldface
FormattedStringFont formattedStringFont = formattedString.GetFont(index, 1);
formattedStringFont.ColorInfo = Color.FromArgb(255, 255, 0, 0);
formattedStringFont.Bold = ExcelDefaultableBoolean.True;