Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.Cells for .NET has exposed a number of classes to provide support for configurable font sources for rendering spreadsheets. Here is the list of classes which have been added with Aspose.Cells for .NET 8.9.1.
With the above‑mentioned changes in place, Aspose.Cells for .NET allows you to set the fonts as detailed below.
Here is a simple usage scenario of the aforementioned methods.
C#
// Defining string variables to store paths to font folders & font file
string fontFolder1 = "D:/Arial";
string fontFolder2 = "D:/Calibri";
string fontFile = "D:/Arial/arial.ttf";
// Setting first font folder with SetFontFolder method
// Second parameter directs the API to search the subfolders for font files
FontConfigs.SetFontFolder(fontFolder1, true);
// Setting both font folders with SetFontFolders method
// Second parameter prevents the API from searching the subfolders for font files
FontConfigs.SetFontFolders(new string[] { fontFolder1, fontFolder2 }, false);
// Defining FolderFontSource
FolderFontSource sourceFolder = new FolderFontSource(fontFolder1, false);
// Defining FileFontSource
FileFontSource sourceFile = new FileFontSource(fontFile);
// Defining MemoryFontSource
MemoryFontSource sourceMemory = new MemoryFontSource(System.IO.File.ReadAllBytes(fontFile));
// Setting font sources
FontConfigs.SetFontSources(new FontSourceBase[] { sourceFolder, sourceFile, sourceMemory });
Aspose.Cells for .NET also allows you to configure font substitution. This mechanism is helpful when a required font is not available on the machine where conversion has to take place. Users can provide a list of font names as alternatives to the originally required font. To achieve this, the Aspose.Cells APIs expose the FontConfigs.SetFontSubstitutes method, which accepts two parameters. The first parameter is of type string and should be the name of the font that needs to be substituted. The second parameter is an array of string; users can provide a list of font names as substitutions for the original font name (specified in the first parameter).
Here is a simple usage scenario of the FontConfigs.SetFontSubstitutes method.
C#
// Substituting the Arial font with Times New Roman & Calibri
FontConfigs.SetFontSubstitutes("Arial", new string[] { "Times New Roman", "Calibri" });
The Aspose.Cells for .NET has also provided a means to gather information on what sources and substitutions have been set.
Aspose.Cells for .NET 8.9.1 allows you to get/set the IFilePathProvider for exporting worksheets to separate HTML files. These new APIs are helpful in scenarios where hyperlinks in one worksheet point to a location in another worksheet, and the application requirement is to render each worksheet to a separate HTML file. Implementing the IFilePathProvider allows you to keep the aforementioned hyperlinks intact regardless of the fact that they point to a location in a separate resultant HTML file.
Below is a simple usage scenario of the HtmlSaveOptions.FilePathProvider property.
C#
// Load a spreadsheet in an instance of Workbook
var book = new Workbook(dir + "sample.xlsx");
// Save each Worksheet to a separate HTML file
for (int i = 0; i < book.Worksheets.Count; i++)
{
book.Worksheets.ActiveSheetIndex = i;
// Create an instance of HtmlSaveOptions & set FilePathProvider property
var options = new HtmlSaveOptions
{
ExportActiveWorksheetOnly = true,
FilePathProvider = new FilePathProvider()
};
// Write HTML file to disc
book.Save(dir + string.Format(@"sheet{0}.html", i), options);
}
Here is how to implement the IFilePathProvider interface.
C#
public class FilePathProvider : IFilePathProvider
{
public FilePathProvider()
{
}
/// <summary>
/// Gets the full path of the file by worksheet name when exporting a worksheet to HTML separately.
/// The references among the worksheets can be exported correctly.
/// </summary>
/// <param name="sheetName">Worksheet name</param>
/// <returns>The full path of the file</returns>
public string GetFullName(string sheetName)
{
if ("Sheet2".Equals(sheetName))
{
return "sheet1.html";
}
else if ("Sheet3".Equals(sheetName))
{
return "sheet2.html";
}
return "";
}
}
Aspose.Cells for .NET API has exposed the Boolean CopyOptions.ReferToDestinationSheet property along with an overload of the Cells.CopyRows method to facilitate the copy‑rows operation when the rows to be copied also contain a chart and its data source. Developers can use these new APIs to point the chart’s data source to the source or destination worksheets.
Below is a simple usage scenario.
C#
// Load a sample spreadsheet in an instance of Workbook
var book = new Workbook(dir + "sample.xlsx");
// Access the worksheet containing the chart & its data source
var source = book.Worksheets[0];
// Add a new worksheet to the collection
var destination = book.Worksheets[book.Worksheets.Add()];
// Initialize CopyOptions and set its ReferToDestinationSheet property to true
CopyOptions options = new CopyOptions
{
ReferToDestinationSheet = true
};
// Copy the rows
destination.Cells.CopyRows(source.Cells, 0, 0, source.Cells.MaxDisplayRange.RowCount, options);
// Save the result on disc
book.Save(dir + "output.xlsx");
Aspose.Cells for .NET 8.9.1 has exposed the Boolean CalculationOptions.Recursive property. Setting this property to true and passing the object to the Workbook.CalculateFormula method directs the Aspose.Cells APIs to calculate dependent cells recursively when calculating cells that depend on other cells.
Below is a simple usage scenario.
C#
// Load a sample spreadsheet in an instance of Workbook
var book = new Workbook(dir + "sample.xlsx");
// Initialize CalculationOptions & set Recursive property to true
var options = new CalculationOptions
{
Recursive = true
};
// Recalculate formulas
book.CalculateFormula(options);
It is advised to use the FontConfigs.SetFontFolder(string, bool) method with the recursive parameter set to false instead.
Use FontConfigs.SetFontFolders(string[], bool) method with the recursive parameter set to false instead.
Use FontConfigs.SetFontSources(FontSourceBase[]) method instead.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.