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 CopyRow 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.

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

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

Bu yöntemi bir sayfa içinde bir satırı, veya başka bir sayfaya kopyalamak için kullanın. CopyRow 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.GetRowHeight 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ü CopyRow yöntemi otomatik olarak satır yüksekliği hakkında da ilgilenir.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Open the existing excel file.
Workbook excelWorkbook1 = new Workbook(dataDir + "book1.xls");
// Get the first worksheet in the workbook.
Worksheet wsTemplate = excelWorkbook1.Worksheets[0];
// Copy the second row with data, formattings, images and drawing objects
// To the 16th row in the worksheet.
wsTemplate.Cells.CopyRow(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.CopyRows yöntemini de kullanabilirsiniz.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// 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.Worksheets["Rows"].Cells;
// Copy the first 3 rows to 7th row
cells.CopyRows(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 CopyColumn 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.

CopyColumn 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 CopyColumn 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.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create another Workbook.
Workbook excelWorkbook1 = new Workbook(dataDir + "book1.xls");
// Get the first worksheet in the book.
Worksheet 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.CopyColumn(ws1.Cells, ws1.Cells.Columns[0].Index, ws1.Cells.Columns[2].Index);
// Autofit the column.
ws1.AutoFitColumn(2);
// Save the excel file.
excelWorkbook1.Save(dataDir + "output.xls");

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

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

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// 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.Worksheets["Columns"].Cells;
// Copy the first 3 columns 7th column
cells.CopyColumns(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 CopyRows ve CopyColumns kullanırken uygun yapıştırma seçeneğini Excel ile benzer şekilde ayarlamayı sağlar.

// 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
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Load sample excel file
Workbook wb = new Workbook(sourceDir + "sampleChangeChartDataSource.xlsx");
// Access the first sheet which contains chart
Worksheet source = wb.Worksheets[0];
// Add another sheet named DestSheet
Worksheet destination = wb.Worksheets.Add("DestSheet");
// Set CopyOptions.ReferToDestinationSheet to true
CopyOptions options = new CopyOptions();
options.ReferToDestinationSheet = true;
// Set PasteOptions
PasteOptions pasteOptions = new PasteOptions();
pasteOptions.PasteType = PasteType.Values;
pasteOptions.OnlyVisibleCells = 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.CopyRows(source.Cells, 0, 0, source.Cells.MaxDisplayRange.RowCount, options, pasteOptions);
// Save workbook in xlsx format
wb.Save(outputDir + "outputChangeChartDataSource.xlsx", SaveFormat.Xlsx);