Private Fonts

GemBox.Spreadsheet provides the FontSettings class for specifying various font related options which are used by a rendering engine when saving a workbook to PDF, XPS or image formats, printing a workbook or converting it to XpsDocument or ImageSource objects.

For example, using the FontSettings.FontsBaseDirectory property you can specify the location where GemBox.Spreadsheet's rendering engine can look for the workbook's font files. This feature is especially useful for medium trust environments, like ASP.NET applications working in Medium Level Trust, where accessing the default font directory for the operating system is restricted.

The following example shows how you can specify the location of a custom font (in this case it contains the Almonte Snow.ttf font file).

Spreadsheet that uses private font
Screenshot of private (not installed) font's usage
using GemBox.Spreadsheet;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        var workbook = new ExcelFile();
        var worksheet = workbook.Worksheets.Add("Private Fonts");

        // Current directory contains a font file.
        FontSettings.FontsBaseDirectory = ".";

        worksheet.Parent.Styles.Normal.Font.Name = "Almonte Snow";
        worksheet.Parent.Styles.Normal.Font.Size = 48 * 20;

        worksheet.Cells[0, 0].Value = "Hello World!";

        workbook.Save("Private Fonts.%OutputFileType%");
    }
}
Imports GemBox.Spreadsheet

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        Dim workbook As New ExcelFile()
        Dim worksheet = workbook.Worksheets.Add("Private Fonts")

        ' Current directory contains a font file.
        FontSettings.FontsBaseDirectory = "."

        worksheet.Parent.Styles.Normal.Font.Name = "Almonte Snow"
        worksheet.Parent.Styles.Normal.Font.Size = 48 * 20

        worksheet.Cells(0, 0).Value = "Hello World!"

        workbook.Save("Private Fonts.%OutputFileType%")
    End Sub
End Module

GemBox.Spreadsheet also supports retrieving fonts that are stored as resources inside the local or referenced assembly by specifying the FontSettings.FontsBaseResourceLocation property. Note; under this property's remarks you can find out how you can use embedded fonts.

See also


Next steps

GemBox.Spreadsheet is a .NET component that enables you to read, write, edit, convert, and print spreadsheet files from your .NET applications using one simple API.

Download Buy