Satır ve Sütun Ekleme, Silme

Giriş

Sıfırdan yeni bir çalışsayfa oluştururken veya mevcut bir çalışsayfada çalışırken, daha fazla veriyi yerleştirmek için ekstra satırlar veya sütunlar eklemeniz veya belirli konumlardan satır veya sütunları silmeniz gerekebilir. Bu gereksinimleri karşılamak için Aspose.Cells, aşağıda tartışılan çok basit bir sınıf ve yöntem seti sağlar.

Satır ve Sütun Yönetimi

Aspose.Cells, bir Microsoft Excel dosyasını temsil eden Workbook adında bir sınıf sağlar. Workbook sınıfı, Excel dosyasındaki her sayfaya erişime izin veren bir Worksheets koleksiyonu içerir. Bir çalışsayfa Worksheet sınıfı tarafından temsil edilir. Worksheet sınıfı, çalışsayfadaki tüm hücreleri temsil eden bir Cells koleksiyonu sağlar.

Cells koleksiyonu, çalışsayfadaki satırları veya sütunları yönetmek için çeşitli yöntemler sağlar, bunlardan bazıları aşağıda daha detaylı olarak tartışılmaktadır.

Bir Satır Ekle

Worksheeta satır eklemek için InsertRow methodunu Cells koleksiyonunun çağrılmasıyla herhangi bir konumda çalıştırın. InsertRow methodu ile yeni satırın ekleneceği satırın dizinini alır.

Aspose::Cells::Startup();
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input
U16String dirPath(u"");
//Path of output
U16String outPath(u"");
//Path of input excel file
U16String sampleInsertingDeletingRowsAndColumns = dirPath + u"sampleInsertingDeletingRowsAndColumns.xlsx";
//Path of output excel file
U16String outputInsertingDeletingRowsAndColumns = outPath + u"outputInsertingDeletingRowsAndColumns.xlsx";
//Read input excel file
Workbook workbook(sampleInsertingDeletingRowsAndColumns);
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.GetWorksheets().Get(0);
//Inserting a column into the worksheet at 2nd position
worksheet.GetCells().InsertColumn(1);
//Save the Excel file.
workbook.Save(outputInsertingDeletingRowsAndColumns);
Aspose::Cells::Cleanup();

Birden Fazla Satır Ekleme

Çalışsayadh birden çok satır eklemek için Cells koleksiyonunun InsertRows methodunu çağırın. InsertRows methodu iki parametre alır:

  • Satır indeksi, yeni satırların ekleneceği satırın indeksi.
  • Satır sayısı, eklenmesi gereken toplam satır sayısı.
Aspose::Cells::Startup();
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input
U16String dirPath(u"");
//Path of output
U16String outPath(u"");
//Path of input excel file
U16String sampleInsertingDeletingRowsAndColumns = dirPath + u"sampleInsertingDeletingRowsAndColumns.xlsx";
//Path of output excel file
U16String outputInsertingDeletingRowsAndColumns = outPath + u"outputInsertingDeletingRowsAndColumns.xlsx";
//Read input excel file
Workbook workbook(sampleInsertingDeletingRowsAndColumns);
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.GetWorksheets().Get(0);
//Inserting 10 rows into the worksheet starting from 3rd row
worksheet.GetCells().InsertRows(2, 10);
//Save the Excel file.
workbook.Save(outputInsertingDeletingRowsAndColumns);
Aspose::Cells::Cleanup();

Birden Fazla Satırı Silme

Çalışma sayfasından birden çok satır silmek için Cells koleksiyonunun DeleteRow methodunu çağırın. DeleteRow methodu iki parametre alır:

  • Satır endeksi, satırların silineceği başlangıç satırının endeksi.
  • satır sayısı, silinmesi gereken toplam satır sayısı
Aspose::Cells::Startup();
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input
U16String dirPath(u"");
//Path of output
U16String outPath(u"");
//Path of input excel file
U16String sampleInsertingDeletingRowsAndColumns = dirPath + u"sampleInsertingDeletingRowsAndColumns.xlsx";
//Path of output excel file
U16String outputInsertingDeletingRowsAndColumns = outPath + u"outputInsertingDeletingRowsAndColumns.xlsx";
//Read input excel file
Workbook workbook(sampleInsertingDeletingRowsAndColumns);
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.GetWorksheets().Get(0);
//Deleting 10 rows from the worksheet starting from 3rd row
worksheet.GetCells().DeleteRows(2, 10);
//Save the Excel file.
workbook.Save(outputInsertingDeletingRowsAndColumns);
Aspose::Cells::Cleanup();

Bir Sütun Eklemek

Geliştiriciler Cells koleksiyonunun InsertColumn methodunu çağırarak çalışsaydh herhangi bir konuma bir sütun da ekleyebilirler. InsertColumn methodu ile yeni sütunun ekleneceği sütunun dizinini alır.

Aspose::Cells::Startup();
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input
U16String dirPath(u"");
//Path of output
U16String outPath(u"");
//Path of input excel file
U16String sampleInsertingDeletingRowsAndColumns = dirPath + u"sampleInsertingDeletingRowsAndColumns.xlsx";
//Path of output excel file
U16String outputInsertingDeletingRowsAndColumns = outPath + u"outputInsertingDeletingRowsAndColumns.xlsx";
//Read input excel file
Workbook workbook(sampleInsertingDeletingRowsAndColumns);
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.GetWorksheets().Get(0);
//Inserting a column into the worksheet at 2nd position
worksheet.GetCells().InsertColumn(1);
//Save the Excel file.
workbook.Save(outputInsertingDeletingRowsAndColumns);
Aspose::Cells::Cleanup();

Bir Sütunu Sil

Herhangi bir konumdan çalışma sayfasından bir sütun silmek için Cells koleksiyonunun DeleteColumn methodunu çağırın. DeleteColumn methodu silinecek sütunun dizinini alır.

Aspose::Cells::Startup();
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input
U16String dirPath(u"");
//Path of output
U16String outPath(u"");
//Path of input excel file
U16String sampleInsertingDeletingRowsAndColumns = dirPath + u"sampleInsertingDeletingRowsAndColumns.xlsx";
//Path of output excel file
U16String outputInsertingDeletingRowsAndColumns = outPath + u"outputInsertingDeletingRowsAndColumns.xlsx";
//Read input excel file
Workbook workbook(sampleInsertingDeletingRowsAndColumns);
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.GetWorksheets().Get(0);
//Deleting a column from the worksheet at 2nd position
worksheet.GetCells().DeleteColumn(1);
//Save the Excel file.
workbook.Save(outputInsertingDeletingRowsAndColumns);
Aspose::Cells::Cleanup();