Syncfusion.XlsIO.Base
Example 


First character of the range.
Last character of the range.
Font to set.

SetFont Method (IRichTextString)

Sets font for range of characters.
Syntax
'Declaration
 
Sub SetFont( _
   ByVal iStartPos As Integer, _
   ByVal iEndPos As Integer, _
   ByVal font As IFont _
) 
'Usage
 
Dim instance As IRichTextString
Dim iStartPos As Integer
Dim iEndPos As Integer
Dim font As IFont
 
instance.SetFont(iStartPos, iEndPos, font)
void SetFont( 
   int iStartPos,
   int iEndPos,
   IFont font
)

Parameters

iStartPos
First character of the range.
iEndPos
Last character of the range.
font
Font to set.
Remarks
To know more about Rich-Text refer Rich-Text Formatting
Example
The following code illustrates how a font can be set to a substring of the RichText.
using Syncfusion.XlsIO;
            
class Program
{
    static void Main()
    {
        using (ExcelEngine excelEngine = new ExcelEngine())
        {
            //Create worksheet
            IApplication application = excelEngine.Excel;
            application.DefaultVersion = ExcelVersion.Excel2013;
            IWorkbook workbook = application.Workbooks.Create(1);
            IWorksheet worksheet = workbook.Worksheets[0];
            
            //Create style
            IStyle style = workbook.Styles.Add("CustomStyle");
            
            //Set rich text
            IRichTextString richText = worksheet["C2"].RichText;
            
            //Set text
            richText.Text = "Sample text";
            
            //Set font
            IFont font = style.Font;
            
            //Set color
            font.Color = ExcelKnownColors.Red;
            
            //Set rich text font
            richText.SetFont(0, 5, font);
            
            //Set color
            font.Color = ExcelKnownColors.Blue;
            
            //Set rich text font
            richText.SetFont(6, 10, font);
            
            //Save and dispose
            workbook.SaveAs("CellFormats.xlsx");
            workbook.Close();
        }
    }
}
AssemblyVersion

Syncfusion.XlsIO.Base: 17.1460.0.32

See Also