ワークブックのレンダリングに対して個別またはプライベートのフォントセットを指定(C++)
Contents
[
Hide
]
可能な使用シナリオ
通常、すべてのワークブックに対してフォントのディレクトリまたはリストを指定しますが、時には個別またはプライベートのフォントセットを指定する必要があります。Aspose.CellsはIndividualFontConfigsクラスを提供し、これを使って個別またはプライベートのフォントをワークブックに指定できます。
ワークブックのレンダリング用に個々またはプライベートなフォントセットを指定する
以下のサンプルコードは、[サンプルのExcelファイル(67338268.xlsx)]を読み込み、そのフォントセットをIndividualFontConfigsクラスを使って指定します。コード内で使用されるフォントの[サンプルフォント(67338271.zip)]や、その結果生成される[出力されたPDF(67338269.pdf)]も確認してください。スクリーンショットは、フォントが正常に認識された場合の出力PDFの様子です。
サンプルコード
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Path of your custom font directory
U16String customFontsDir(u"C:\\TempDir\\CustomFonts");
// Specify individual font configs custom font directory
IndividualFontConfigs fontConfigs;
// If you comment this line or if custom font directory is wrong or
// if it does not contain required font then output pdf will not be rendered correctly
fontConfigs.SetFontFolder(customFontsDir, false);
// Specify load options with font configs
LoadOptions opts(LoadFormat::Xlsx);
opts.SetFontConfigs(fontConfigs);
// Load the sample Excel file with individual font configs
Workbook wb(u"sampleSpecifyIndividualOrPrivateSetOfFontsForWorkbookRendering.xlsx", opts);
// Save to PDF format
wb.Save(u"outputSpecifyIndividualOrPrivateSetOfFontsForWorkbookRendering.pdf", SaveFormat::Pdf);
std::cout << "Workbook saved to PDF with custom font configurations successfully!" << std::endl;
Aspose::Cells::Cleanup();
}