در این مثال، نحوه تبدیل نمودار Excel به JPEG در C++ را بررسی خواهیم کرد. نمودارها راه خوبی برای نمایش اطلاعات هستند و می توانید نمودارها را در MS Excel اضافه کنید. می توانید نمودار را در اکسل به JPEG در C++ با استفاده از فراخوانی های ساده API در هر سیستم عاملی مانند مایکروسافت ویندوز و لینوکس و غیره ذخیره کنید.
مراحل تبدیل نمودار اکسل به JPEG در C++
- Aspose.Cells.Cpp را با ابزار مدیریت بسته NuGet نصب کنید
- ارجاع به فضای نام Aspose::Cells را وارد کنید
- شیء Workbook Class را نمونهسازی کنید و فایل اکسل را با نمودار داخل آن بارگذاری کنید
- برای دسترسی به نمودار داخل کاربرگ انتخاب شده، شیء Chart Class را نمونهسازی کنید
- نمودار XLSX را در JPEG در C++ ذخیره کنید
با استفاده از مثال ساده زیر، می توانید * نمودار اکسل را به JPG در C++* بسیار سریع و آسان در چند تماس API تبدیل کنید. همچنین میتوانید نمودار را بهعنوان تصویر با استفاده از ++C به فرمتهای تصویری PNG و BMP صادر کنید.
کد برای تبدیل نمودار اکسل به 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); | |
} | |
}; |
در مثال قبلی، با نحوه تبدیل XLSX به XPS با استفاده از ++C آشنا شدیم. این مثال روی نحوه تبدیل نمودار XLSX به JPEG در C++ تمرکز دارد.