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
- Kopyalamak istediğiniz satırı veya sütunu seçin.
- Satırları veya sütunları kopyalamak için tıklayınkopyala üzerindeStandart araç çubuğu veya tuşuna basınCTRL+C.
- Seçiminizi kopyalamak istediğiniz yerin altından veya sağından bir satır veya sütun seçin.
- Satırları veya sütunları kopyalarken,Cells kopyalandı üzerindeSokmak Menü.
Microsoft Excel ile Yapıştırma Seçeneklerini Kullanarak Satırları ve Sütunları Yapıştırma
- Kopyalamak istediğiniz verileri veya diğer öznitelikleri içeren hücreleri seçin.
- Giriş sekmesinde,kopyala.
- İstediğiniz alandaki ilk hücreye tıklayın.yapıştırmak ne kopyaladın
- Giriş sekmesinde, yanındaki oka tıklayın.Yapıştırmak ve ardından seçinYapıştırmak Özel.
- seçinseçenekler İstediğiniz.
Aspose.Cells’i kullanma
Tek Satırları Kopyalama
Aspose.Cells şunları sağlar:Satırı Kopyala 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.
buSatırı Kopyalayöntem 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. buSatırı Kopyalayöntem 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.
kullanarak kaynak satır yüksekliğini alan adımı atlayabilirsiniz.Cells.GetRowHeight yöntemini kullanarak hedef satır yüksekliğini ayarlar ve ardındanCells.SetRowHeight yöntem olarakSatırı Kopyalamethod otomatik olarak satır yüksekliği ile 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"); |
Microsoft Excel’de olduğu gibi, satırları kopyalarken ilgili resimleri, çizelgeleri veya diğer çizim nesnelerini not etmek önemlidir:
- Kaynak satır dizini 5 ise, resim, grafik vb. üç satırda bulunuyorsa kopyalanır (başlangıç satır dizini 4 ve bitiş satır dizini 6’dır).
- Hedef satırdaki mevcut resimler, çizelgeler vb. kaldırılmayacaktır.
Birden Çok Satırı Kopyalama
kullanırken birden çok satırı yeni bir hedefe de kopyalayabilirsiniz.Cells.CopyRowskopyalanacak kaynak satır sayısını belirtmek için tamsayı türünde ek bir parametre alan yöntem.
// 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ı Kopyalama
Aspose.Cells şunları sağlar:Sütunu Kopyala 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.
buSütunu Kopyalayöntem aşağıdaki parametreleri alır:
- kaynakCellsnesne,
- kaynak sütun dizini ve
- hedef sütun dizini.
KullanSütunu Kopyalabir 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.
// 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ütunu Kopyalama
BenzerCells.CopyRows yöntemi, Aspose.Cells API’leri ayrıca şunları sağlar:Cells.CopyColumnsyö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-.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ç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çeneğinin ayarlanmasına izin verir.
// 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); |