Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.
Mon Sep 27, 2021 6:11 pm
Hello,
I cannot find a way to style a single excel cell in different styles. For example I need to make only some part of the string bold and leave the rest unbold in one cell. I can only access Cells not characters.
Can you please help with this one?
Thanks
- Attachments
-
- Some part of cell is in bold
- excel1.PNG (2.93 KiB) Viewed 2361 times
-
zaheen555
-
- Posts: 6
- Joined: Mon Sep 27, 2021 5:31 pm
Tue Sep 28, 2021 7:08 am
Hello,
Thanks for your inquiry.
Please use the following code to achieve your requirement. If there is any question, please feel free to write back.
- Code: Select all
Workbook workbook = new Workbook();
workbook.LoadFromFile(inputfile);
//Get the A1 cell
CellRange cell = workbook.Worksheets[0].Range["A1"];
//Get the cell font name
string fontName = cell.Style.Font.FontName;
//Create a font object in workbook
ExcelFont font = workbook.CreateFont();
font.FontName = fontName;
//Set bold style
font.IsBold = true;
//Get the RichText
RichText richText = cell.RichText;
//Set the font for the specified character range
richText.SetFont(0, 12, font);
//Save the file
workbook.SaveToFile("output.xlsx", FileFormat.Version2013);
Sincerely,
Annika
E-iceblue support team
-
Annika.Zhou
-
- Posts: 1651
- Joined: Wed Apr 07, 2021 2:50 am
Fri Oct 08, 2021 6:35 am
Hello,
Hope you're doing well!
How is your issue going? Did the code we provided work for you? Any feedback will be greatly appreciated.
Sincerely,
Annika
E-iceblue support team
-
Annika.Zhou
-
- Posts: 1651
- Joined: Wed Apr 07, 2021 2:50 am