Renderizza sequenza di pagine utilizzando le proprietà PageIndex e PageCount di ImageOrPrintOptions con C++

Possibili Scenari di Utilizzo

È possibile rendere una sequenza di pagine del file Excel in immagini utilizzando Aspose.Cells con le proprietà ImageOrPrintOptions.GetPageIndex() e ImageOrPrintOptions.GetPageCount(). Queste proprietà sono utili quando ci sono ad esempio migliaia di pagine nel foglio di lavoro ma si desidera renderne solo alcune. Questo non solo risparmierà tempo di elaborazione ma risparmierà anche l’utilizzo della memoria del processo di rendering.

Rendere la sequenza di pagine utilizzando le proprietà PageIndex e PageCount di ImageOrPrintOptions

Il seguente codice di esempio carica il file Excel di esempio e rende solo le pagine 4, 5, 6 e 7 utilizzando le proprietà ImageOrPrintOptions.GetPageIndex() e ImageOrPrintOptions.GetPageCount(). Ecco le pagine renderizzate generate dal codice.

todo:image_alt_text todo:image_alt_text
todo:image_alt_text todo:image_alt_text

Codice di Esempio

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

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

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

    Workbook wb(srcDir + u"sampleImageOrPrintOptions_PageIndexPageCount.xlsx");

    Worksheet ws = wb.GetWorksheets().Get(0);

    ImageOrPrintOptions opts;
    opts.SetPageIndex(3);
    opts.SetPageCount(4);
    opts.SetImageType(ImageType::Png);

    SheetRender sr(ws, opts);

    for (int i = opts.GetPageIndex(); i < sr.GetPageCount(); i++)
    {
        std::wstring pageNum = std::to_wstring(i + 1);
        U16String filePath = outDir + U16String(u"outputImage-") + 
            U16String(reinterpret_cast<const char16_t*>(pageNum.c_str())) + 
            U16String(u".png");
        sr.ToImage(i, filePath);
    }

    std::cout << "Images generated successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}