Satırları veya Aralığı Kopyalarken Grafiklerin Veri Kaynağını Hedef Çalışma Sayfasına Değiştirme
Olası Kullanım Senaryoları
Grafik içeren satırları veya aralığı yeni çalışma sayfasına kopyaladığınızda, grafiklerin veri kaynağı değişmez. Örneğin, grafiklerin veri kaynağı =Sheet1!$A$1:$B$4 ise, satırları veya aralığı yeni çalışma sayfasına kopyaladıktan sonra, veri kaynağı aynı kalır yani =Sheet1!$A$1:$B$4 olarak kalır. Bu da Microsoft Excel davranışıdır. Ancak, yeni hedef çalışma sayfasına işaret etmesini istiyorsanız, Cells.CopyRows() yöntemini çağırırken CopyOptions.ReferToDestinationSheet özelliğini true olarak ayarlayın. Şimdi hedef çalışma sayfanız DestSheet ise, grafiklerinizin veri kaynağı =Sheet1!$A$1:$B$4 yerine =DestSheet!$A$1:$B$4 olacaktır.
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ırları veya aralığı yeni çalışma sayfasına kopyalarken CopyOptions.ReferToDestinationSheet özelliğinin kullanımını açıklar. Kod, örnek excel dosyasını kullanır ve çıktı excel dosyasını oluşturur. Ekran görüntüsü, çıktı excel dosyasındaki grafik veri kaynağının ArtSeyre yapılması gösterir.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
String dataDir = Utils.getDataDir(ChangeDataSource.class); | |
// Load sample excel file | |
Workbook wb = new Workbook(dataDir + "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("DestSheet"); | |
// Set CopyOptions.ReferToDestinationSheet to true | |
CopyOptions options = new CopyOptions(); | |
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(dataDir + "output.xlsx", SaveFormat.XLSX); |