IndividualFontConfigs.SetFontSources
IndividualFontConfigs.SetFontSources method
Sets the fonts sources.
public void SetFontSources(FontSourceBase[] sources)
Parameter | Type | Description |
---|---|---|
sources | FontSourceBase[] | An array of sources that contain TrueType fonts. |
Examples
namespace AsposeCellsExamples
{
using Aspose.Cells;
using System;
using System.IO;
public class IndividualFontConfigsMethodSetFontSourcesWithFontSourceBaseDemo
{
public static void Run()
{
// Create individual font configurations
IndividualFontConfigs fontConfigs = new IndividualFontConfigs();
// Prepare font sources - using both folder and memory font sources
FontSourceBase[] fontSources = new FontSourceBase[]
{
new FolderFontSource(@"C:\Windows\Fonts", false),
new MemoryFontSource(File.ReadAllBytes(@"C:\Windows\Fonts\arial.ttf"))
};
try
{
// Call SetFontSources with the prepared font sources
fontConfigs.SetFontSources(fontSources);
Console.WriteLine("Font sources set successfully:");
foreach (var source in fontConfigs.GetFontSources())
{
if (source is FolderFontSource folderSource)
{
Console.WriteLine($"- Folder: {folderSource.FolderPath} (Recursive: {folderSource.ScanSubFolders})");
}
else if (source is MemoryFontSource memorySource)
{
Console.WriteLine($"- Memory font with data length: {memorySource.FontData.Length} bytes");
}
}
// Create a workbook to demonstrate the effect
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
// Use a font that should be available from the sources
Style style = workbook.CreateStyle();
style.Font.Name = "Arial";
style.Font.Size = 14;
worksheet.Cells["A1"].SetStyle(style);
worksheet.Cells["A1"].Value = "Text using font from custom sources";
worksheet.Cells["A2"].Value = "This demonstrates SetFontSources with FontSourceBase[]";
// Save the workbook
workbook.Save("SetFontSourcesDemo.xlsx");
}
catch (Exception ex)
{
Console.WriteLine($"Error executing SetFontSources method: {ex.Message}");
}
}
}
}
See Also
- class FontSourceBase
- class IndividualFontConfigs
- namespace Aspose.Cells
- assembly Aspose.Cells