En este ejemplo, exploraremos cómo convertir el gráfico Excel a JPEG en C++. Los gráficos son una buena manera de representar la información y puede agregar gráficos en MS Excel. Puede guardar el gráfico en Excel a JPEG en C++ usando simples llamadas API en cualquier sistema operativo como Microsoft Windows y Linux, etc.
Pasos para convertir un gráfico de Excel a JPEG en C++
- Instale Aspose.Cells.Cpp con la herramienta Administrador de paquetes NuGet
- Incluir una referencia al espacio de nombres Aspose::Cells
- Cree una instancia del objeto Workbook Class y cargue el archivo de Excel con el gráfico dentro
- Cree una instancia del objeto Chart Class para acceder al gráfico dentro de la hoja de trabajo seleccionada
- Guarde el gráfico XLSX en JPEG en C++
Usando el siguiente ejemplo simple, puede convertir un gráfico de Excel a JPG en C++ muy rápida y fácilmente en unas pocas llamadas a la API. También puede exportar el gráfico como imagen usando C++ a los formatos de imagen PNG y BMP.
Código para convertir gráfico de Excel a 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); | |
} | |
}; |
En el ejemplo anterior, aprendimos sobre Cómo convertir XLSX a XPS usando C++. Este ejemplo se centra en cómo convertir un gráfico XLSX a JPEG en C++.