Other API Samples

Live SpreadsheetGear API Samples

Range Samples Formatting and Other Cell Features Rich-Text Formatting (RTF) Font

Demonstrates uniquely formatting specific sub-portions of text in a cell.

// Create a new workbook and some local variables.
SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
SpreadsheetGear.IWorksheet worksheet = workbook.ActiveWorksheet;
SpreadsheetGear.IRange cells = worksheet.Cells;

// Get a reference to cell A1.
SpreadsheetGear.IRange cell = cells["A1"];

// Add text to the cell.
cell.Value = "SpreadsheetGear Engine for .NET";

// Set font size for entire text to 24 points.
cell.Font.Size = 24;

// Set "Spreadsheet" text to dark blue.
SpreadsheetGear.ICharacters spreadsheetChars = cell.GetCharacters(0, 11);
spreadsheetChars.Font.Color = SpreadsheetGear.Color.FromArgb(255, 0, 0, 128);

// Set "Gear" text to a shade of red.
SpreadsheetGear.ICharacters gearChars = cell.GetCharacters(11, 4);
gearChars.Font.Color = SpreadsheetGear.Color.FromArgb(255, 233, 14, 14);

// Set "Engine" text style.
SpreadsheetGear.ICharacters engineChars = cell.GetCharacters(16, 6);
engineChars.Font.Bold = true;

// Set "for" text style.
SpreadsheetGear.ICharacters forChars = cell.GetCharacters(23, 3);
forChars.Font.Underline = SpreadsheetGear.UnderlineStyle.Single;

// Set ".NET Standard" text style.
SpreadsheetGear.ICharacters netStandardChars = cell.GetCharacters(27, 4);
netStandardChars.Font.Italic = true;

// AutoFit the column.
cell.EntireColumn.AutoFit();
Run This Sample
Render Image

Generate an image representation of the results of this sample, which uses the SpreadsheetGear.Drawing.Image class to convert ranges, charts and shapes to images.


Download File

Download an Excel Open XML Workbook (*.xlsx) file with the results of this sample.

Related Samples