إنشاء Microsoft® مخططات Excel وتحويلها إلى صور عبر C++

قم بتحويل مخططات مستندات Excel إلى صور بالإضافة إلى إنشاء مخططات بما في ذلك المخططات الدائرية والهرمية والخطية والفقاعية ضمن التطبيقات المستندة إلى C++.

 

باستخدام مخططات Excel، يمكن للمرء الحصول على الصورة الأكبر وتحليل البيانات بسهولة لاتخاذ القرارات الصحيحة. C++ مكتبة اكسيل يدعم إنشاء مخططات مختلفة مدرجة حسب التعداد Aspose::Cells::المخططات::ChartType بما في ذلك المخططات المساحية والشريطية والدائرية والهرمية والخطية والفقاعية. علاوة على ذلك، لتحويل المخططات إلى صور، يوفر API أ ToImage طريقة إلى تنسيق الصورة المطلوبة.

إنشاء مخططات Excel

عملية إنشاء مخطط Excel هي إنشاء مثيل لـ فئة المصنف واختر المطلوب ورقة عمل . أضف الرسم البياني باستخدام أضف طريقة مع المعلمات ذات الصلة بما في ذلك نوع المخطط. الوصول إلى الرسم البياني عبر الفهرس و يضيف مصدر البيانات للمخطط.

C++ كود لإنشاء مخططات Excel
Aspose::Cells::Startup();
// Path of output XLSM file
U16String outputChartTypeCustom = u"sourceFile.xlsm";
// Create a new workbook
Workbook wkb;
// Get first worksheet which is created by default
Worksheet wks = wkb.GetWorksheets().Get(0);
// Adding sample values to cells
wks.GetCells().Get(u"A1").PutValue(50);
wks.GetCells().Get(u"A2").PutValue(100);
wks.GetCells().Get(u"A3").PutValue(150);
wks.GetCells().Get(u"B1").PutValue(4);
wks.GetCells().Get(u"B2").PutValue(20);
wks.GetCells().Get(u"B3").PutValue(50);
// Adding a chart to the worksheet
int chartIndex = wks.GetCharts().Add(Aspose::Cells::Charts::ChartType::Column, 5, 0, 20, 8);
// Accessing the instance of the newly added chart
Chart chart = wks.GetCharts().Get(chartIndex);
// Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.GetNSeries().Add(u"A1:B3", true);
// Saving the ODS file
wkb.Save(outputChartTypeCustom);
Aspose::Cells::Cleanup();

تحويل المخططات إلى صور

لتحويل الرسوم البيانية، قم أولاً بإنشاء مخطط من النوع ذي الصلة باستخدام الكود أعلاه أو الوصول إليه من الورقة ذات الصلة. حدد مسار حفظ الإخراج للصورة واستخدم طريقة ToImage للتحويل.

C++ كود لتحويل مخططات الاكسل
Aspose::Cells::Startup();
// Output directory path
U16String outDir = u"..\\OutputDirectory\\";
// Path of output image file
U16String outputChartImage = outDir + u"out1image.png";
// Create a new workbook
Workbook wkb;
// Get first worksheet which is created by default
Worksheet wks = wkb.GetWorksheets().Get(0);
// Adding sample values to cells
wks.GetCells().Get(u"A1").PutValue(50);
wks.GetCells().Get(u"A2").PutValue(100);
wks.GetCells().Get(u"A3").PutValue(150);
wks.GetCells().Get(u"B1").PutValue(4);
wks.GetCells().Get(u"B2").PutValue(20);
wks.GetCells().Get(u"B3").PutValue(50);
// Adding a chart to the worksheet
int chartIndex = wks.GetCharts().Add(Aspose::Cells::Charts::ChartType::Column, 5, 0, 20, 8);
// Accessing the instance of the newly added chart
Chart chart = wks.GetCharts().Get(chartIndex);
// Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.GetNSeries().Add(u"A1:B3", true);
// Saving the chart to image file
chart.ToImage(outputChartImage, ImageType::Png);
Aspose::Cells::Cleanup();