在没有内容时输出空白页面(C++)
Contents
[
Hide
]
可能的使用场景
如果工作表为空,Aspose.Cells在导出工作表为图像时不会打印任何内容。可以通过设置ImageOrPrintOptions.GetOutputBlankPageWhenNothingToPrint()属性改变此行为。当将其设置为true时,将会打印空白页面。
当没有要打印的内容时输出空白页
以下示例代码创建了一个空工作簿,其包含一个空工作表,并在设置ImageOrPrintOptions.GetOutputBlankPageWhenNothingToPrint()属性为true后将其渲染为图像。因此,生成了空白页面,你可以在下方的图片中看到。
示例代码
#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;
}