قراءة وتلاعب رسومات Excel 2016
سيناريوهات الاستخدام المحتملة
يدعم Aspose.Cells قراءة وتلاعب مخططات Microsoft Excel 2016 التي لا توجد في Microsoft Excel 2013 أو الإصدارات السابقة.
قراءة وتلاعب شكل بيانات Excel 2016
تحمل الشفرة المثالية التالية ملف الإكسل العيني الذي يحتوي على رسوم Excel 2016 في ورقة العمل الأولى. تقرأ جميع الرسوم وتقوم بتغيير عنوانها حسب نوعها. اللقطة الشاشة التالية تظهر ملف الإكسل العيني قبل تنفيذ الشفرة المثالية. كما يمكنك رؤية، عنوان الرسم البياني هو نفسه لجميع الرسوم.
اللقطة الشاشة التالية تظهر ملف الإكسل الناتج بعد تنفيذ الشفرة. كما ترون، تم تغيير عنوان الرسم البياني حسب نوعه.
الكود المثالي
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
Aspose::Cells::Startup(); | |
//Source directory path | |
U16String srcDir(u"..\\Data\\01_SourceDirectory\\"); | |
//Output directory path | |
U16String outDir(u"..\\Data\\02_OutputDirectory\\"); | |
//Path of input excel file | |
U16String sampleReadAndManipulateExcel2016Charts = srcDir + u"sampleReadAndManipulateExcel2016Charts.xlsx"; | |
//Path of output excel file | |
U16String outputReadAndManipulateExcel2016Charts = outDir + u"outputReadAndManipulateExcel2016Charts.xlsx"; | |
// Load sample Excel file containing Excel 2016 charts | |
Workbook workbook(sampleReadAndManipulateExcel2016Charts); | |
// Access the first worksheet which contains the charts | |
Worksheet worksheet = workbook.GetWorksheets().Get(0); | |
// Access all charts one by one and read their types | |
for (int i = 0; i < worksheet.GetCharts().GetCount(); i++) | |
{ | |
// Access the chart | |
Chart ch = worksheet.GetCharts().Get(i); | |
//Get the chart type | |
ChartType chartType = ch.GetType(); | |
//Convert chart type enum to string | |
U16String strChartType = u""; | |
switch (chartType) | |
{ | |
case Aspose::Cells::Charts::ChartType::BoxWhisker: | |
strChartType = u"BoxWhisker"; | |
break; | |
case Aspose::Cells::Charts::ChartType::Histogram: | |
strChartType = u"Histogram"; | |
break; | |
case Aspose::Cells::Charts::ChartType::Sunburst: | |
strChartType = u"Sunburst"; | |
break; | |
case Aspose::Cells::Charts::ChartType::Treemap: | |
strChartType = u"Treemap"; | |
break; | |
case Aspose::Cells::Charts::ChartType::Waterfall: | |
strChartType = u"Waterfall"; | |
break; | |
default: | |
break; | |
} | |
// Print chart type | |
std::cout << strChartType.ToUtf8() << std::endl; | |
// Change the title of the charts as per their types | |
U16String strTitle = u"Chart Type is " + strChartType; | |
ch.GetTitle().SetText(strTitle); | |
} | |
// Save the workbook | |
workbook.Save(outputReadAndManipulateExcel2016Charts); | |
Aspose::Cells::Cleanup(); |
مخرجات الوحدة
إليك الإخراج على الكونسول من خلال شفرة العينة أعلاه عند تنفيذها مع ملف الإكسل العيني المقدم.
Waterfall
Treemap
Sunburst
Histogram
BoxWhisker