Šiame pavyzdyje išnagrinėsime, kaip konvertuoti Excel diagramą į JPEG C++. Diagramos yra geras būdas pateikti informaciją ir galite pridėti diagramas į MS Excel. Galite išsaugoti diagramą Excel JPEG formatu C++, naudodami paprastus API iškvietimus bet kuriose operacinėse sistemose, pvz., Microsoft Windows, Linux ir kt.
Veiksmai, kaip konvertuoti Excel diagramą į JPEG C++
- Įdiekite Aspose.Cells.Cpp naudodami NuGet paketų tvarkyklės įrankį
- Įtraukite nuorodą į Aspose::Cells vardų erdvę
- Sukurkite objektą Workbook Class ir įkelkite Excel failą su jame esančia diagrama
- Sukurkite objektą Chart Class, kad pasiektumėte diagramą pasirinktame darbalapyje
- Išsaugokite XLSX diagramą JPEG formatu C++
Naudodami šį paprastą pavyzdį galite labai greitai ir lengvai paversti Excel diagramą į JPG C++ per kelis API iškvietimus. Taip pat galite eksportuoti diagramą kaip vaizdą naudodami C++ į PNG ir BMP vaizdo formatus.
Kodas, skirtas konvertuoti Excel diagramą į JPEG 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); | |
} | |
}; |
Ankstesniame pavyzdyje sužinojome apie Kaip konvertuoti XLSX į XPS naudojant C++. Šiame pavyzdyje daugiausia dėmesio skiriama kaip konvertuoti XLSX diagramą į JPEG C++.