Excelファイルをレンダリングする際にフォントの置換ワーニングを取得

ExcelファイルをPDFにレンダリングする際、フォントの置き換えに関する警告を受け取るには、IWarningCallbackインターフェースを実装し、PdfSaveOptions.WarningCallbackプロパティを実装したインターフェースに設定します。

以下のスクリーンショットは、次のコードで使用する元のExcelファイルを示しています。セルA6およびA7には、Microsoft Excelによって正しくレンダリングされないフォントでテキストが含まれています。

すべてのフォントが正しくレンダリングされているわけではありません
todo:image_alt_text
Aspose.Cellsは、セルA6とA7のフォントを適切なフォントで置き換えます。
置き換えフォント
todo:image_alt_text

ソースファイルと出力PDFのダウンロード

以下のリンクからソースExcelファイルと出力PDFをダウンロードできます

コード

次のコードは、IWarningCallbackを実装し、PdfSaveOptions.WarningCallbackプロパティを実装したインターフェースに設定します。これにより、Aspose.Cellsが任意のセルでフォントが置き換えられるたびに、Aspose.CellsはWarningCallback.Warning()メソッド内で警告を発生させます。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
public class GetWarningsForFontSubstitution : IWarningCallback
{
public void Warning(WarningInfo info)
{
if (info.WarningType == WarningType.FontSubstitution)
{
Debug.WriteLine("WARNING INFO: " + info.Description);
}
}
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Workbook workbook = new Workbook(dataDir + "source.xlsx");
PdfSaveOptions options = new PdfSaveOptions();
options.WarningCallback = new GetWarningsForFontSubstitution();
dataDir = dataDir + "output_out.pdf";
workbook.Save(dataDir, 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 ].