Satır ve Sütunları Kopyalama

Giriş

Bazen, bir çalışma sayfasında tüm çalışma sayfasını kopyalamadan satır ve sütunları kopyalamanız gerekir. Aspose.Cells ile, çalışma kitapları arasında veya içinde satır ve sütunları kopyalamak mümkündür. Bir satır (veya sütun) kopyalandığında, içindeki veriler, güncellenmiş referanslarla formülleri - ve değerleri, yorumları, biçimlendirmeyi, gizli hücreleri, görüntüleri ve diğer çizim nesnelerini içeren veriler de kopyalanır.

Microsoft Excel ile Satırları ve Sütunları Nasıl Kopyalanır

  1. Kopyalamak istediğiniz satırı veya sütunu seçin.
  2. Satır veya sütunları kopyalamak için Standart araç çubuğunda Kopyala‘yı tıklayın veya CTRL+C‘ye basın.
  3. Kopyalamak istediğiniz seçimin altında veya sağındaki bir satır veya sütunu seçin.
  4. Satır veya sütunları kopyalarken, Ekle menüsünde Kopyalanan Hücreler‘i tıklayın.

Microsoft Excel ile Yapıştırma Seçenekleri Kullanarak Satır ve Sütunları Nasıl Yapıştırılır

  1. Kopyalamak istediğiniz veri veya diğer özelliklere sahip hücreleri seçin.
  2. Ana sekmede Kopyala‘yı tıklayın.
  3. Kopyaladığınız şeyi yapıştırmak istediğiniz alanın ilk hücresine tıklayın.
  4. Ana sekmede Yapıştır‘ın yanındaki oku tıklayın ve ardından Yapıştırma‘yı seçin.
  5. İstediğiniz seçenekleri seçin.

Aspose.Cells for .NET Kullanarak Satır ve Sütunları Nasıl Kopyalanır

Tek Satırları Nasıl Kopyalanır

Aspose.Cells, Cells sınıfının copy_row yöntemini sağlar. Bu yöntem, formüller, değerler, yorumlar, hücre biçimleri, gizli hücreler, resimler ve diğer çizim nesneleri de dahil olmak üzere tüm türde verileri kaynaktan hedefe kopyalar.

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

  • kaynak Cells nesnesi
  • kaynak satır endeksi, ve
  • hedef satır endeksi.

Bu yöntemi bir sayfa içinde bir satırı, veya başka bir sayfaya kopyalamak için kullanın. copy_row yöntemi, örneğin Microsoft Excel’de olduğu gibi benzer şekilde çalışır. Bu nedenle, örneğin, hedef satırın yüksekliğini açıkça ayarlamanıza gerek yok, o değer de kopyalanır.

Aşağıdaki örnek, bir çalışsayfasında bir satır kopyalamayı gösterir. Bir şablon Microsoft Excel dosyası kullanır ve ikinci satırı (veri, biçimlendirme, yorumlar, resimler vb. ile birlikte) kopyalar ve aynı çalışsayfadaki 12. satıra yapıştırır.

Cells.get_row_height yöntemi kullanarak kaynak satırın yüksekliğini almayı ve ardından hedef satırın yüksekliğini ayarlamayı dikkate almanız gerekmez, çünkü copy_row yöntemi otomatik olarak satır yüksekliği hakkında da ilgilenir.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Open the existing excel file.
excelWorkbook1 = Workbook(dataDir + "book1.xls")
# Get the first worksheet in the workbook.
wsTemplate = excelWorkbook1.worksheets[0]
# Copy the second row with data, formattings, images and drawing objects
# To the 16th row in the worksheet.
wsTemplate.cells.copy_row(wsTemplate.cells, 1, 15)
# Save the excel file.
excelWorkbook1.save(dataDir + "output.xls")

Birden Fazla Satırın Nasıl Kopyalanacağı

Ayrıca, ek bir tamsayı parametresi alarak yeni bir hedefe birden fazla satır kopyalarken Cells.copy_rows yöntemini de kullanabilirsiniz.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create an instance of Workbook class by loading the existing spreadsheet
workbook = Workbook(dataDir + "aspose-sample.xlsx")
# Get the cells collection of worksheet by name Rows
cells = workbook.worksheets.get("Rows").cells
# Copy the first 3 rows to 7th row
cells.copy_rows(cells, 0, 6, 3)
# Save the result on disc
workbook.save(dataDir + "output_out.xlsx")

Sütunları Kopyalamak

Aspose.Cells, Cells sınıfının copy_column yöntemini sağlar, bu yöntem formüller, güncellenmiş referanslar içeren değerler, yorumlar, hücre biçimleri, gizli hücreler, resimler ve diğer çizim nesneleri dahil olmak üzere tüm türde verileri kaynaktan hedefe kopyalar.

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

  • kaynak Cells nesnesi
  • kaynak sütun indeksi ve
  • hedef sütun indeksi.

Bir çalışma sayfası içinde bir sütunu kopyalamak veya başka bir çalışma sayfasına kopyalamak için copy_column yöntemini kullanın.

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

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create another Workbook.
excelWorkbook1 = Workbook(dataDir + "book1.xls")
# Get the first worksheet in the book.
ws1 = excelWorkbook1.worksheets[0]
# Copy the first column from the first worksheet of the first workbook into
# The first worksheet of the second workbook.
ws1.cells.copy_column(ws1.cells, ws1.cells.columns[0].index, ws1.cells.columns[2].index)
# Autofit the column.
ws1.auto_fit_column(2)
# Save the excel file.
excelWorkbook1.save(dataDir + "output.xls")

Birden Çok Sütun Nasıl Kopyalanır

Cells.copy_rows yöntemine benzer şekilde, Aspose.Cells API’leri ayrıca birden çok kaynak sütunu yeni bir konuma kopyalamak için Cells.copy_columns yöntemini sağlar.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create an instance of Workbook class by loading the existing spreadsheet
workbook = Workbook(dataDir + "aspose-sample.xlsx")
# Get the cells collection of worksheet by name Columns
cells = workbook.worksheets.get("Columns").cells
# Copy the first 3 columns 7th column
cells.copy_columns(cells, 0, 6, 3)
# Save the result on disc
workbook.save(dataDir + "output_out.xlsx")

Yapıştırma Seçenekleri ile Satır ve Sütunların Nasıl Yapıştırılacağı

Aspose.Cells şimdi, PasteOptions işlevler copy_rows ve copy_columns kullanırken uygun yapıştırma seçeneğini Excel ile benzer şekilde ayarlamayı sağlar.

from aspose.cells import CopyOptions, PasteOptions, PasteType, SaveFormat, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
# Source directory
sourceDir = RunExamples.Get_SourceDirectory()
# Output directory
outputDir = RunExamples.Get_OutputDirectory()
# Load sample excel file
wb = Workbook(sourceDir + "sampleChangeChartDataSource.xlsx")
# Access the first sheet which contains chart
source = wb.worksheets[0]
# Add another sheet named DestSheet
destination = wb.worksheets.add("DestSheet")
# Set CopyOptions.ReferToDestinationSheet to true
options = CopyOptions()
options.refer_to_destination_sheet = True
# Set PasteOptions
pasteOptions = PasteOptions()
pasteOptions.paste_type = PasteType.VALUES
pasteOptions.only_visible_cells = 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.cells.copy_rows(source.cells, 0, 0, source.cells.max_display_range.row_count, options, pasteOptions)
# Save workbook in xlsx format
wb.save(outputDir + "outputChangeChartDataSource.xlsx", SaveFormat.XLSX)