ExcelCell Inline Text Formatting

Using GemBox.Spreadsheet you can apply font formatting (size, color, font type, italic and strikeout properties, different levels of boldness, underlining, subscript and superscript) to individual characters and words.

Following example shows how to format individual characters and words within a cell.

Screenshot

ExcelCell Inline Text Formatting Screenshot

See the full code below, use RUN EXAMPLE to execute.


1using GemBox.Spreadsheet;
2using System;
3using System.IO;
4
5class Sample
6{
7    [STAThread]
8    static void Main(string[] args)
9    {
10        // If using Professional version, put your serial key below.
11        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
12
13        ExcelFile ef = new ExcelFile();
14        ExcelWorksheet ws = ef.Worksheets.Add("Inline Text Formatting");
15
16        ws.Cells[0, 0].Value = "Inline text formatting examples:";
17        ws.PrintOptions.PrintGridlines = true;
18
19        // Column width of 20 characters.
20        ws.Columns[0].Width = 20 * 256;
21
22        ws.Cells[2, 0].Value = "This is big and red text!";
23
24        // Apply size to 'big and red' part of text
25        ws.Cells[2, 0].GetCharacters(8, 11).Font.Size = 400;
26
27        // Apply color to 'red' part of text
28        ws.Cells[2, 0].GetCharacters(16, 3).Font.Color = SpreadsheetColor.FromName(ColorName.Red);
29
30        // Format cell content
31        ws.Cells[4, 0].Value = "Formatting selected characters with GemBox.Spreadsheet component.";
32        ws.Cells[4, 0].Style.Font.Color = SpreadsheetColor.FromName(ColorName.Blue);
33        ws.Cells[4, 0].Style.Font.Italic = true;
34        ws.Cells[4, 0].Style.WrapText = true;
35
36        // Get characters from index 36 to the end of string
37        FormattedCharacterRange characters = ws.Cells[4, 0].GetCharacters(36);
38
39        // Apply color and underline to selected characters
40        characters.Font.Color = SpreadsheetColor.FromName(ColorName.Orange);
41        characters.Font.UnderlineStyle = UnderlineStyle.Single;
42
43        // Write selected characters
44        ws.Cells[6, 0].Value = "Selected characters: " + characters.Text;
45
46        ef.Save("Inline Text Formatting.xlsx");
47    }
48}
1Imports GemBox.Spreadsheet
2Imports System.IO
3
4Module Samples
5
6    Sub Main()
7
8        ' If using Professional version, put your serial key below.
9        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")
10
11        Dim ef As ExcelFile = New ExcelFile
12        Dim ws As ExcelWorksheet = ef.Worksheets.Add("Inline Text Formatting")
13
14        ws.Cells(0, 0).Value = "Inline text formatting examples:"
15        ws.PrintOptions.PrintGridlines = True
16
17        ' Column width of 20 characters.
18        ws.Columns(0).Width = 20 * 256
19
20        ws.Cells(2, 0).Value = "This is big and red text!"
21
22        ' Apply size to 'big and red' part of text
23        ws.Cells(2, 0).GetCharacters(8, 11).Font.Size = 400
24
25        ' Apply color to 'red' part of text
26        ws.Cells(2, 0).GetCharacters(16, 3).Font.Color = SpreadsheetColor.FromName(ColorName.Red)
27
28        ' Format cell content
29        ws.Cells(4, 0).Value = "Formatting selected characters with GemBox.Spreadsheet component."
30        ws.Cells(4, 0).Style.Font.Color = SpreadsheetColor.FromName(ColorName.Blue)
31        ws.Cells(4, 0).Style.Font.Italic = True
32        ws.Cells(4, 0).Style.WrapText = True
33
34        ' Get characters from index 36 to the end of string
35        Dim characters As FormattedCharacterRange = ws.Cells(4, 0).GetCharacters(36)
36
37        ' Apply color and underline to selected characters
38        characters.Font.Color = SpreadsheetColor.FromName(ColorName.Orange)
39        characters.Font.UnderlineStyle = UnderlineStyle.Single
40
41        ' Write selected characters
42        ws.Cells(6, 0).Value = "Selected characters: " + characters.Text
43
44        ef.Save("Inline Text Formatting.xlsx")
45
46    End Sub
47
48End Module

Check next sample or find out more about GemBox.Spreadsheet and GemBox Software.