Satırları ve Sütunları Kopyalama

Giriş

Bazen, tüm çalışma sayfasını kopyalamadan çalışma sayfasındaki satırları ve sütunları kopyalamanız gerekir. Aspose.Cells ile çalışma kitaplarının içinde veya arasında satır ve sütun kopyalamak mümkündür.

Bir satır (veya sütun) kopyalandığında, güncellenmiş referanslara sahip formüller ve değerler, yorumlar, biçimlendirme, gizli hücreler, resimler ve diğer çizim nesneleri de dahil olmak üzere içerdiği veriler de kopyalanır.

Microsoft Excel ile Satırları ve Sütunları Kopyalama

  1. Kopyalamak istediğiniz satırı veya sütunu seçin.
  2. Satırları veya sütunları kopyalamak için tıklayınkopyala üzerindeStandart araç çubuğu veya tuşuna basınCTRL+C.
  3. Seçiminizi kopyalamak istediğiniz yerin altından veya sağından bir satır veya sütun seçin.
  4. Satırları veya sütunları kopyalarken,Cells kopyalandı üzerindeSokmak Menü.

Tek Satır Kopyalama

Aspose.Cells şunları sağlar:kopya satırı yöntemiCellssınıf. Bu yöntem, formüller, değerler, yorumlar, hücre formatları, gizli hücreler, resimler ve diğer çizim nesneleri dahil olmak üzere tüm veri türlerini kaynak satırdan hedef satıra kopyalar.

bukopya satırı yöntemi aşağıdaki parametreleri alır:

  • kaynakCellsnesne,
  • kaynak satır dizini ve
  • hedef satır dizini.

Bir sayfadaki bir satırı veya başka bir sayfaya kopyalamak için bu yöntemi kullanın. bukopya satırı yöntemi, Microsoft Excel’e benzer şekilde çalışır. Yani, örneğin, hedef satırın yüksekliğini açıkça ayarlamanıza gerek yoktur, o değer de kopyalanır.

Aşağıdaki örnek, çalışma sayfasındaki bir satırın nasıl kopyalanacağını gösterir. Bir şablon Microsoft Excel dosyası kullanır ve ikinci satırı kopyalar (veriler, biçimlendirme, yorumlar, resimler vb. İle birlikte) ve aynı çalışma sayfasındaki 12. satıra yapıştırır.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(CopyingRows.class) + "rows_cloumns/";
// Create a new Workbook.
Workbook excelWorkbook = new Workbook(dataDir + "book1.xls");
// Get the first worksheet in the workbook.
Worksheet wsTemplate = excelWorkbook.getWorksheets().get(0);
// Copy the second row with data, formating, images and drawing objects to the 12th row in the worksheet.
wsTemplate.getCells().copyRow(wsTemplate.getCells(), 2, 10);
// Save the excel file.
excelWorkbook.save(dataDir + "CopyingRows_out.xls");
// Print message
System.out.println("Row and Column copied successfully.");

Aşağıdaki kod çalıştırıldığında aşağıdaki çıktı üretilir.

Satır, en yüksek düzeyde kesinlik ve doğrulukla kopyalanır

yapılacaklar:resim_alternatif_metin

Birden Çok Satırı Kopyalama

kullanırken birden çok satırı yeni bir hedefe de kopyalayabilirsiniz.Cells.copyRows kopyalanacak kaynak satır sayısını belirtmek için tamsayı türünde ek bir parametre alan yöntem.

Aşağıda, 3 satır veri içeren giriş e-tablosunun bir anlık görüntüsü bulunurken, aşağıda verilen kod parçacığı, 3 satırın tümünü 7. sıradan başlayarak yeni bir konuma kopyalar.

yapılacaklar:resim_alternatif_metin

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CopyingMultipleRows.class);
// Create an instance of Workbook class by loading the existing spreadsheet
Workbook workbook = new Workbook(dataDir + "aspose-sample.xlsx");
// Get the cells collection of worksheet by name Rows
Cells cells = workbook.getWorksheets().get("Rows").getCells();
// Copy the first 3 rows to 7th row
cells.copyRows(cells, 0, 6, 3);
// Save the result on disc
workbook.save(dataDir + "output.xlsx");

İşte yukarıdaki kod parçacığını yürüttükten sonra ortaya çıkan elektronik tablo görünümü.

yapılacaklar:resim_alternatif_metin

Tek Sütunu Kopyalama

Aspose.Cells şunları sağlar:kopya sütunu yöntemiCellsBu yöntem, güncellenmiş referanslarla formüller ve değerler, yorumlar, hücre biçimleri, gizli hücreler, resimler ve diğer çizim nesneleri dahil olmak üzere tüm veri türlerini kaynak sütundan hedef sütuna kopyalar.

bukopya sütunu yöntemi aşağıdaki parametreleri alır:

  • kaynakCellsnesne,
  • kaynak sütun dizini ve
  • hedef sütun dizini.

Kullankopya sütunu bir sayfadaki bir sütunu veya başka bir sayfaya kopyalama yöntemi.

Bu örnek, bir çalışma sayfasındaki bir sütunu kopyalar ve başka bir çalışma kitabındaki bir çalışma sayfasına yapıştırır.

Bir sütun bir çalışma kitabından diğerine kopyalanır

yapılacaklar:resim_alternatif_metin

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(CopyingColumns.class) + "rows_cloumns/";
// Create a new Workbook.
Workbook excelWorkbook = new Workbook(dataDir + "book1.xls");
// Get the first worksheet in the workbook.
Worksheet wsTemplate = excelWorkbook.getWorksheets().get(0);
// Copy the first column from the first worksheet of the first workbook into the first worksheet of the second workbook.
wsTemplate.getCells().copyColumn(wsTemplate.getCells(), 1, 4);
// Save the excel file.
excelWorkbook.save(dataDir + "CopyingColumns_out.xls");
// Print message
System.out.println("Row and Column copied successfully.");

Birden Çok Sütunu Kopyalama

BenzerCells.copyRows yöntemi, Aspose.Cells API’leri ayrıca şunları sağlar:Cells.copyColumns yöntemi, birden çok kaynak sütunu yeni bir konuma kopyalamak için kullanılır.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CopyingMultipleColumns.class);
// Create an instance of Workbook class by loading the existing spreadsheet
Workbook workbook = new Workbook(dataDir + "aspose-sample.xlsx");
// Get the cells collection of worksheet by name Columns
Cells cells = workbook.getWorksheets().get("Columns").getCells();
// Copy the first 3 columns 7th column
cells.copyColumns(cells, 0, 6, 3);
// Save the result on disc
workbook.save(dataDir + "output.xlsx");

Kaynak ve sonuçtaki e-tabloların Excel’de nasıl göründüğü aşağıda açıklanmıştır.

yapılacaklar:resim_alternatif_metin

yapılacaklar:resim_alternatif_metin

Yapıştırma Seçenekleriyle Satırları/Sütunları Yapıştırma

Aspose.Cells şimdi sağlıyorSeçenekleri Yapıştır fonksiyonları kullanırkenSatırları Kopyala veSütunları Kopyala. Excel’e benzer uygun yapıştırma seçeneklerinin ayarlanmasına izin verir.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Load some excel file
Workbook wb = new Workbook("book1.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);
// Set PasteOptions
PasteOptions pasteOptions = new PasteOptions();
pasteOptions.setPasteType(PasteType.VALUES);
pasteOptions.setOnlyVisibleCells(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, pasteOptions);
// Save workbook in xlsx format
wb.save("destination.xlsx", SaveFormat.XLSX);