Convert Excel Chart to Image and PDF Formats using C++

Aspose Team is pleased to announce the release of Aspose.Cells for C++ 18.8.0. This release supports rendering charts to image and PDF formats. It also includes a number of fixes and other enhancements that further improve the overall stability of the API. Please check the detailed release notes in order to get an idea about what is new and what has been enhanced with this revision of Aspose.Cells for C++.

While you are downloading the API build to give it a try, here is a list of added features along with a few code snippets for quick testing.

Excel Chart to Image in C++

Aspose.Cells for C++ supports to create a verity of MS Excel charts. The Chart.toImage method has a verity of overloads to support simple as well as advanced rendering. In order to demonstrate the usage of Aspose.Cells APIs to render the charts in image format, we will create a Column chart first and then render it to image format as per the following snippet.

// Create a new workbook
intrusive_ptr workbook = Factory::CreateIWorkbook();
// Get first worksheet which is created by default
intrusive_ptr worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
// Adding sample values to cells
worksheet->GetICells()->GetObjectByIndex(new String("A1"))->PutValue(50);
worksheet->GetICells()->GetObjectByIndex(new String("A2"))->PutValue(100);
worksheet->GetICells()->GetObjectByIndex(new String("A3"))->PutValue(150);
worksheet->GetICells()->GetObjectByIndex(new String("B1"))->PutValue(4);
worksheet->GetICells()->GetObjectByIndex(new String("B2"))->PutValue(20);
worksheet->GetICells()->GetObjectByIndex(new String("B3"))->PutValue(50);
// Adding a chart to the worksheet
int chartIndex = worksheet->GetICharts()->Add(Aspose::Cells::Charts::ChartType::ChartType_Column, 5, 0, 20, 8);
// Accessing the instance of the newly added chart
intrusive_ptr chart = worksheet->GetICharts()->GetObjectByIndex(chartIndex);
// Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart->GetNISeries()->Add(new String("A1:B3"), true);

// Output directory path
StringPtr outDir = new String("..\\Data\\02_OutputDirectory\\");
// Path of output image file
StringPtr outputChartImage = outDir->StringAppend(new String("out1image.png"));
// Saving the chart to image file
chart->ToImage(outputChartImage, Aspose::Cells::System::Drawing::Imaging::ImageFormat::GetPng());

See the document on how to convert a chart to image format for your reference.

Excel Chart to PDF in C++

In order to render the chart to PDF format, the Aspose.Cells APIs have exposed the Chart.ToPdf method with ability to store the resultant PDF on disc path or Stream.

// Path of output pdf file
StringPtr outputPdfFile = outDir->StringAppend(new String("out1pdf.pdf"));
// Saving chart to PDF

See the document on how to convert a chart to PDF file format for your reference.

Aspose.Cells for C++ Resources

The resources, you may need to accomplish your tasks:

Keeping the Aspose tradition, you are welcome to shape the upcoming releases of Aspose.Cells for C++ API by posting your suggestions and concerns in the Aspose.Cells support forum.