In questo esempio, esploreremo come convertire Excel Grafico in JPEG in C++. I grafici sono un buon modo per rappresentare le informazioni e puoi aggiungere grafici in MS Excel. Puoi salvare il grafico in Excel in JPEG in C++ utilizzando semplici chiamate API in qualsiasi sistema operativo come Microsoft Windows e Linux ecc.
Passaggi per convertire il grafico Excel in JPEG in C++
- Installa Aspose.Cells.Cpp con lo strumento Gestione pacchetti NuGet
- Includi il riferimento allo spazio dei nomi Aspose::Cells
- Crea un’istanza dell’oggetto Workbook Class e carica il file Excel con il grafico al suo interno
- Crea un’istanza dell’oggetto Chart Class per accedere al grafico all’interno del foglio di lavoro selezionato
- Salva il grafico XLSX in JPEG in C++
Utilizzando il seguente semplice esempio, puoi convertire il grafico Excel in JPG in C++ molto rapidamente e facilmente in poche chiamate API. Puoi anche esportare il grafico come immagine utilizzando C++ nei formati immagine PNG e BMP.
Codice per convertire il grafico Excel in JPEG in 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); | |
} | |
}; |
Nell’esempio precedente, abbiamo appreso di Come convertire XLSX in XPS usando C++. Questo esempio si concentra su come convertire il grafico XLSX in JPEG in C++.