この例では、C++でExcelチャートをJPEGに変換する方法を説明します。グラフは情報を表す良い方法であり、MSExcelでグラフを追加できます。 Microsoft WindowsやLinuxなどのオペレーティングシステムで簡単なAPI呼び出しを使用して、ExcelのグラフをC++のJPEGに保存できます。
C++でExcelチャートをJPEGに変換する手順
- NuGetパッケージマネージャーツールを使用してAspose.Cells.Cppをインストールします
- Aspose::Cells名前空間への参照を含める
- Workbook Classオブジェクトをインスタンス化し、グラフを含むExcelファイルを読み込みます
- Chart Classオブジェクトをインスタンス化して、選択したワークシート内のグラフにアクセスします
- XLSXチャートをC++でJPEGに保存
次の簡単な例を使用すると、いくつかのAPI呼び出しでExcelチャートをC++でJPGに非常に迅速かつ簡単に変換できます。 C++を使用してグラフを画像としてPNGおよびBMP画像形式にエクスポートすることもできます。
C++でExcelチャートをJPEGに変換するコード
#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); | |
} | |
}; |
前の例では、C++を使用してXLSXをXPSに変換する方法について学習しました。この例では、C++でXLSXチャートをJPEGに変換する方法に焦点を当てています。