Excelファイルのレンダリング時にフォント置換の警告を取得する
ExcelファイルをPDFにレンダリングする際のフォント置換警告を取得するには、IWarningCallbackインターフェースを実装し、PdfSaveOptions.warningCallbackプロパティに設定します。
以下のスクリーンショットは、次のコードで使用する元のExcelファイルを示しています。セルA6およびA7には、Microsoft Excelによって正しくレンダリングされないフォントでテキストが含まれています。
すべてのフォントが正しくレンダリングされているわけではありません |
---|
![]() |
Aspose.Cellsは、セルA6とA7のフォントを適切なフォントで置き換えます。 |
置き換えフォント |
---|
![]() |
ソースファイルと出力PDFのダウンロード
以下のリンクからソースExcelファイルと出力PDFをダウンロードできます
コード
以下のコードは、IWarningCallbackを実装し、PdfSaveOptions.warningCallbackプロパティに設定しています。これにより、セル内でフォントが置換された場合、Aspose.CellsはWarningCallback.Warning()メソッド内で警告を発します。
const AsposeCells = require("aspose.cells.node");
const path = require("path");
class GetWarningsForFontSubstitution {
static warning(info) {
if (info.getType() === AsposeCells.WarningType.FontSubstitution) {
console.log("WARNING INFO: " + info.getDescription());
}
}
static run() {
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "source.xlsx");
const workbook = new AsposeCells.Workbook(filePath);
const options = new AsposeCells.PdfSaveOptions();
options.setWarningCallback(GetWarningsForFontSubstitution);
const outputFilePath = path.join(dataDir, "output_out.pdf");
workbook.save(outputFilePath, options);
}
}
出力
ExcelファイルをPDFに変換した後、警告は次のようにデバッグコンソールに出力されます。
WARNING INFO: Font substitution: Font [ Athene Logos; Regular ] has been substituted in Cell [ A6 ] in Sheet [ Sheet1 ].
WARNING INFO: Font substitution: Font [ B Traffic; Regular ] has been substituted in Cell [ A7 ] in Sheet [ Sheet1 ].