We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

TextBoxShape Apply Color Or Bold to text

I am looking for a way to apply Color or Boldness to specific text inside of a ITextBoxShape. Does anyone know how to possibly do this. 


I need to be able to do something like 


TITLE:

RED text

regular text


1 Reply 1 reply marked as answer

KK Konduru Keerthi Konduru Ravichandra Raju Syncfusion Team March 28, 2023 12:24 PM UTC

Hi Fernando,


Yes. You can format the text of a text box through Syncfusion XlsIO. We have given below, a simple code snippet to achieve this.


Code Snippet:


using (ExcelEngine excelEngine = new ExcelEngine())

{

    IApplication application = excelEngine.Excel;

    application.DefaultVersion = ExcelVersion.Excel2013;

    IWorkbook workbook = application.Workbooks.Create(1);

    IWorksheet sheet = workbook.Worksheets[0];

 

    ITextBoxShape textbox = sheet.TextBoxes.AddTextBox(2, 2, 30, 200);

    textbox.Text = "TextBox";

 

    IRichTextString richText = textbox.RichText;

    IFont font = workbook.CreateFont();

    font.Bold = true;

    font.RGBColor = Color.Red;

    richText.SetFont(0, 6, font);

 

    //Saving the Excel to the MemoryStream

    MemoryStream stream = new MemoryStream();

    workbook.SaveAs(stream);

 

    //Set the position as '0'.

    stream.Position = 0;

 

    //Download the Excel file in the browser

    FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel");

    fileStreamResult.FileDownloadName = "Output.xlsx";

    return fileStreamResult;

}


Regards,

Keerthi.


Marked as answer
Loader.
Live Chat Icon For mobile
Up arrow icon