Grafiğin Veri Kaynağını Hedef Çalışma Sayfası Olarak Değiştirme ve Satır veya Aralık Kopyalama ile C++ Kullanma
Olası Kullanım Senaryoları
Grafiklerin veri kaynağı, satır veya aralıkları yeni bir çalışma sayfasına kopyaladığınızda değişmez. Örneğin, grafik veri kaynağı =Sheet1!$A$1:$B$4 ise, satırlar veya aralıklar yeni bir çalışma sayfasına kopyalandığında veri kaynağı aynı kalır yani =Sheet1!$A$1:$B$4 olur. Bu, Microsoft Excel’de de aynı davranıştır. Ancak, yeni hedef çalışma sayfasını göstermek istiyorsanız, CopyOptions.GetReferToDestinationSheet() özelliğini kullanın ve Cells.CopyRows() metodunu çağırırken true olarak ayarlayın. Hedef çalışma sayfanız DestSheet ise, grafiğin veri kaynağı =Sheet1!$A$1:$B$4’ten =DestSheet!$A$1:$B$4' e değişecektir.
Satırları veya Aralıkları Kopyalarken Grafiğin Veri Kaynağını Hedef Çalışma Sayfasına Değiştirme
Aşağıdaki örnek kod, grafik içeren satır veya aralıkları yeni bir çalışma sayfasına kopyalarken CopyOptions.GetReferToDestinationSheet() özelliğinin kullanımını açıklamaktadır. Kod, örnek excel dosyasını kullanmakta ve çıktı excel dosyasını üretmektedir.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Load sample Excel file
Workbook wb(srcDir + u"sample.xlsx");
// Access the first sheet which contains chart
Worksheet source = wb.GetWorksheets().Get(0);
// Add another sheet named DestSheet
Worksheet destination = wb.GetWorksheets().Add(u"DestSheet");
// Set CopyOptions.ReferToDestinationSheet to true
CopyOptions options;
options.SetReferToDestinationSheet(true);
// Copy all the rows of source worksheet to destination worksheet which includes chart as well
// The chart data source will now refer to DestSheet
destination.GetCells().CopyRows(source.GetCells(), 0, 0, source.GetCells().GetMaxDisplayRange().GetRowCount(), options);
// Save workbook in xlsx format
wb.Save(srcDir + u"output_out.xlsx", SaveFormat::Xlsx);
std::cout << "Workbook saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}