Render Worksheet to Graphic Context with C++

Contents
[ ]

The following code illustrates how to use Aspose.Cells to render a worksheet to a graphic context. Once you execute the code, it will render the entire worksheet, fill the remaining empty space with a blue color in the graphics context, and save the image as the OutputImage_out.png file. You can use any source Excel file to try this code. Please also read the comments inside the code for better understanding.

#include <iostream>
#include <memory>
#include "Aspose.Cells.h"

using namespace Aspose::Cells;
using namespace Aspose::Cells::Rendering;

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

    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
    U16String outDir(u"..\\Data\\02_OutputDirectory\\");

    Workbook workbook(srcDir + u"SampleBook.xlsx");
    Worksheet worksheet = workbook.GetWorksheets().Get(0);

    ImageOrPrintOptions opts;
    opts.SetOnePagePerSheet(true);
    opts.SetImageType(ImageType::Png);

    SheetRender sr(worksheet, opts);
    sr.ToImage(0, outDir + u"OutputImage_out.png");

    Aspose::Cells::Cleanup();
}