Satır ve Sütun Ekleme, Silme

Giriş

Sıfırdan yeni bir çalışma sayfası oluştururken veya mevcut bir çalışma sayfası üzerinde çalışırken, daha fazla veriyi barındırmak için fazladan satır veya sütun eklememiz gerekebilir. Tersine, çalışma sayfasında belirtilen konumlardaki satırları veya sütunları da silmemiz gerekebilir. Bu gereklilikleri yerine getirmek için Aspose.Cells, aşağıda tartışılan çok basit bir sınıflar ve yöntemler seti sağlar.

Satırları ve Sütunları Yönetme

Aspose.Cells bir sınıf sağlar,IÇalışma Kitabı , bu bir Microsoft Excel dosyasını temsil eder. buIÇalışma Kitabı sınıf bir içerirIÇalışma Sayfaları bir Excel dosyasındaki her çalışma sayfasına erişim sağlayan koleksiyon. Bir çalışma sayfası şununla temsil edilir:IÇalışma Sayfası sınıf. buIÇalışma Sayfası sınıf bir sağlarICell’lerçalışma sayfasındaki tüm hücreleri temsil eden koleksiyon.

buICell’lerkoleksiyon, bir çalışma sayfasındaki satırları ve sütunları yönetmek için çeşitli yöntemler sağlar. Bunlardan bazıları aşağıda tartışılmaktadır.

Satır Ekle

çağırarak çalışma sayfasına herhangi bir konumda bir satır ekleyin.Satır Ekle yöntemiICell’ler Toplamak. buSatır Eklemethod yeni satırın ekleneceği satırın indeksini alır.

//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input excel file
StringPtr sampleInsertingDeletingRowsAndColumns = dirPath->StringAppend(new String("sampleInsertingDeletingRowsAndColumns.xlsx"));
//Path of output excel file
StringPtr outputInsertingDeletingRowsAndColumns = outPath->StringAppend(new String("outputInsertingDeletingRowsAndColumns.xlsx"));
//Read input excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleInsertingDeletingRowsAndColumns);
//Accessing the first worksheet in the Excel file
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
//Inserting a row into the worksheet at 3rd position
worksheet->GetICells()->InsertRow(2);
//Save the Excel file.
workbook->Save(outputInsertingDeletingRowsAndColumns);

Birden Çok Satır Ekleme

Bir çalışma sayfasına birden çok satır eklemek içinSatır Ekle yöntemiICell’ler Toplamak. buSatır Ekleyöntem iki parametre alır:

  • Satır dizini, yeni satırların ekleneceği satırın dizini.
  • Satır sayısı, eklenmesi gereken toplam satır sayısı.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input excel file
StringPtr sampleInsertingDeletingRowsAndColumns = dirPath->StringAppend(new String("sampleInsertingDeletingRowsAndColumns.xlsx"));
//Path of output excel file
StringPtr outputInsertingDeletingRowsAndColumns = outPath->StringAppend(new String("outputInsertingDeletingRowsAndColumns.xlsx"));
//Read input excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleInsertingDeletingRowsAndColumns);
//Accessing the first worksheet in the Excel file
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
//Inserting 10 rows into the worksheet starting from 3rd row
worksheet->GetICells()->InsertRows(2, 10);
//Save the Excel file.
workbook->Save(outputInsertingDeletingRowsAndColumns);

Birden Çok Satırı Silme

Bir çalışma sayfasından birden çok satırı silmek içinSatırları Sil yöntemiICell’ler Toplamak. buSatırları Silyöntem iki parametre alır:

  • Satır dizini, satırların silineceği satırın dizini.
  • Satır sayısı, silinmesi gereken toplam satır sayısı.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input excel file
StringPtr sampleInsertingDeletingRowsAndColumns = dirPath->StringAppend(new String("sampleInsertingDeletingRowsAndColumns.xlsx"));
//Path of output excel file
StringPtr outputInsertingDeletingRowsAndColumns = outPath->StringAppend(new String("outputInsertingDeletingRowsAndColumns.xlsx"));
//Read input excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleInsertingDeletingRowsAndColumns);
//Accessing the first worksheet in the Excel file
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
//Deleting 10 rows from the worksheet starting from 3rd row
worksheet->GetICells()->DeleteRows(2, 10);
//Save the Excel file.
workbook->Save(outputInsertingDeletingRowsAndColumns);

Sütun Ekle

Geliştiriciler ayrıca, çalışma sayfasına herhangi bir konumda şunu çağırarak bir sütun ekleyebilir:Sütun Ekle yöntemiICell’ler Toplamak.Sütun Eklemethod yeni kolonun ekleneceği kolonun indeksini alır.

//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input excel file
StringPtr sampleInsertingDeletingRowsAndColumns = dirPath->StringAppend(new String("sampleInsertingDeletingRowsAndColumns.xlsx"));
//Path of output excel file
StringPtr outputInsertingDeletingRowsAndColumns = outPath->StringAppend(new String("outputInsertingDeletingRowsAndColumns.xlsx"));
//Read input excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleInsertingDeletingRowsAndColumns);
//Accessing the first worksheet in the Excel file
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
//Inserting a column into the worksheet at 2nd position
worksheet->GetICells()->InsertColumn(1);
//Save the Excel file.
workbook->Save(outputInsertingDeletingRowsAndColumns);

Bir Sütunu Sil

Herhangi bir konumdaki çalışma sayfasından bir sütunu silmek içinSütunu Sil yöntemiICell’ler Toplamak. buSütunu SilYöntem, silinecek sütunun dizinini alır.

//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input excel file
StringPtr sampleDeleteColumn = dirPath->StringAppend(new String("sampleInsertingDeletingRowsAndColumns.xlsx"));
//Path of output excel file
StringPtr outputDeleteColumn = outPath->StringAppend(new String("outputInsertingDeletingRowsAndColumns.xlsx"));
//Read input excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleDeleteColumn);
//Accessing the first worksheet in the Excel file
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
//Deleting a column from the worksheet at 2nd position
worksheet->GetICells()->DeleteColumn(4);
//Save the Excel file.
workbook->Save(outputDeleteColumn);