Microsoft® Excel Grafikleri Oluşturun ve C++ aracılığıyla Görsellere Dönüştürün
C++ tabanlı uygulamalarda Excel belge grafiklerini görüntülere dönüştürün ve Pasta, Piramit, Çizgi ve Kabarcık grafikleri içeren grafikler oluşturun.
Excel grafiklerini kullanarak büyük resmi görebilir ve doğru kararları almak için verileri kolayca analiz edebilirsiniz. C++ Excel Kütüphanesi tarafından listelenen farklı grafikler oluşturmayı destekler enum Aspose::Cells::Charts::ChartType alan, çubuk, pasta, piramit, çizgi ve kabarcık grafikleri dahil. Ayrıca, grafiklerin görsellere dönüştürülmesi için API, Hayal etmek yöntemi gerekli görüntü formatına dönüştürün.
Excel Grafikleri Oluşturun
Excel grafiği oluşturma işlemi, bir örneğini oluşturmaktır. Çalışma kitabı sınıfı ve istediğinizi seçin Çalışma kağıdı . Kullanarak grafiği ekleyin Yöntem ekle grafik türü de dahil olmak üzere ilgili parametrelerle. Grafiğe indeks aracılığıyla erişin ve Eklemek grafiğin veri kaynağı.
C++ Excel Grafikleri Oluşturma Kodu
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(); |
Grafikleri Görsellere Dönüştürün
Grafikleri dönüştürmek için öncelikle yukarıdaki kodu kullanarak ilgili türde grafik oluşturun veya ilgili sayfadan erişin. Görüntü için çıktı kaydetme yolunu tanımlayın ve dönüştürme için ToImage yöntemini kullanın.
C++ Excel Grafiklerini Dönüştürme Kodu
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(); |