Kako pretvoriti Excel grafikon u JPEG u C++

U ovom primjeru istražit ćemo kako pretvoriti grafikon Excel u JPEG u C++. Grafikoni su dobar način predstavljanja informacija, a grafikone možete dodati u MS Excelu. Grafikon u Excelu možete spremiti u JPEG u C++ koristeći jednostavne API pozive u bilo kojem operativnom sustavu kao što su Microsoft Windows i Linux itd.

Koraci za pretvaranje Excel grafikona u JPEG u C++

  1. Instalirajte Aspose.Cells.Cpp s alatom NuGet Package Manager
  2. Uključi referencu na prostor naziva Aspose::Cells
  3. Instancirajte objekt Workbook Class i učitajte Excel datoteku s grafikonom unutar nje
  4. Instancirajte objekt Chart Class za pristup grafikonu unutar odabranog radnog lista
  5. Spremite XLSX grafikon u JPEG u C++

Pomoću sljedećeg jednostavnog primjera možete pretvoriti Excel grafikon u JPG u C++ vrlo brzo i jednostavno u nekoliko API poziva. Također možete izvesti grafikon kao sliku koristeći C++ u PNG i BMP slikovne formate.

Kod za pretvaranje Excel grafikona u JPEG u C++

#pragma once
#include "Aspose.Cells.h"
class ExcelChart
{
public:
static void ConvertExcelChartToImage()
{
// Set Aspose.Cells API License
intrusive_ptr<License> CellsRenderingLicense = new License();
CellsRenderingLicense->SetLicense(new String("Aspose.Cells.NET.lic"));
// Instantiate the Workbook obkect to load XLSX with chart in it
intrusive_ptr<IWorkbook> ChartToImageWb = Factory::CreateIWorkbook(new String("input.xlsx"));
// Acces the default worksheet with chart in it
intrusive_ptr<IWorksheet> worksheet = ChartToImageWb->GetIWorksheets()->GetObjectByIndex(0);
// Create instnce of Chart class to access the first chart inside selected excel sheet
intrusive_ptr<Aspose::Cells::Charts::IChart> chart = worksheet->GetICharts()->GetObjectByIndex(0);
// Create an instance of ImageOrPrintOptions to set output image type
intrusive_ptr <IImageOrPrintOptions> imageOrPrintOptions = Factory::CreateIImageOrPrintOptions();
imageOrPrintOptions->SetChartImageType(Aspose::Cells::Systems::Drawing::Imaging::ImageFormat::GetJpeg());
// Save XLSX chart as JPEG image
chart->ToImage(new String("ExcelChartToImage.jpg"), imageOrPrintOptions);
}
};

U prethodnom smo primjeru učili o Kako pretvoriti XLSX u XPS koristeći C++. Ovi se primjeri fokusiraju na kako pretvoriti XLSX grafikon u JPEG u C++.

 Hrvatski