出力する内容がない場合に空白ページを出力する(C++)

可能な使用シナリオ

シートが空の場合、Aspose.Cellsはワークシートを画像にエクスポートするときに何も印刷しません。この動作はImageOrPrintOptions.GetOutputBlankPageWhenNothingToPrint()プロパティを使用して変更できます。これをtrueに設定すると、空白ページが印刷されます。

印刷するものがない場合、空白ページを出力

以下のサンプルコードは、空のワークブック(空のワークシートを含む)を作成し、ImageOrPrintOptions.GetOutputBlankPageWhenNothingToPrint()プロパティをtrueに設定した後、その空のワークシートを画像にレンダリングします。その結果、印刷すべき内容がないため空白ページが生成され、その画像は以下のように表示されます。

todo:image_alt_text

サンプルコード

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C

    // Output directory
    U16String outputDir(u"..\\Data\\02_OutputDirectory\\");

    // Create workbook
    Workbook wb;

    // Access first worksheet - it is an empty sheet
    Worksheet ws = wb.GetWorksheets().Get(0);

    // Specify image or print options
    // Since the sheet is blank, we will set OutputBlankPageWhenNothingToPrint to true
    // So that an empty page gets printed
    ImageOrPrintOptions opts;
    opts.SetImageType(Drawing::ImageType::Png);
    opts.SetOutputBlankPageWhenNothingToPrint(true);

    // Render empty sheet to png image
    SheetRender sr(ws, opts);
    sr.ToImage(0, outputDir + u"OutputBlankPageWhenNothingToPrint.png");

    std::cout << "Blank page rendered to PNG successfully!" << std::endl;

    Aspose::Cells::Cleanup();
    return 0;
}