Dans cet exemple, nous allons explorer comment convertir Excel Chart en JPEG en C++. Les graphiques sont un bon moyen de représenter les informations et vous pouvez ajouter des graphiques dans MS Excel. Vous pouvez enregistrer le graphique dans Excel au format JPEG en C++ à l’aide d’appels d’API simples dans tous les systèmes d’exploitation tels que Microsoft Windows et Linux, etc.
Étapes pour convertir un graphique Excel en JPEG en C++
- Installez Aspose.Cells.Cpp avec l’outil NuGet package Manager
- Inclure une référence à l’espace de noms Aspose::Cells
- Instanciez l’objet Workbook Class et chargez le fichier Excel avec le graphique à l’intérieur
- Instanciez l’objet Chart Class pour accéder au graphique dans la feuille de calcul sélectionnée
- Enregistrer le graphique XLSX au format JPEG en C++
En utilisant l’exemple simple suivant, vous pouvez convertir un graphique Excel en JPG en C++ très rapidement et facilement en quelques appels d’API. Vous pouvez également exporter le graphique en tant qu’image à l’aide de C++ vers les formats d’image PNG et BMP.
Code pour convertir un graphique Excel en JPEG en 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); | |
} | |
}; |
Dans l’exemple précédent, nous avons découvert Comment convertir XLSX en XPS en utilisant C++. Cet exemple se concentre sur comment convertir un graphique XLSX en JPEG en C++.