Excelワークシートで行を挿入または削除する

Contents
[ ]

Aspose.Cellsでは、行を挿入したり削除するための2つのメソッドが提供されています: Cells.InsertRows と Cells.DeleteRows。これらのメソッドはパフォーマンスが最適化されており、非常に迅速に作業を行います。

行を挿入または削除する場合、Cells.InsertRow や DeleteRow のメソッドをループ内で使用する代わりに、常に Cells.InsertRows と Cells.DeleteRows のメソッドを使用することをお勧めします。

Aspose.CellsはMicrosoft Excelと同様に動作します。行または列が追加されると、ワークシートの内容は下方向や右方向にシフトされます。行または列が削除されると、ワークシートの内容は上方向や左方向にシフトされます。行が追加または削除された場合、他のワークシートやセル内の参照が更新されます。

// 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);
// Instantiate a Workbook object.
// Load a template file.
Workbook workbook = new Workbook(dataDir+ "book1.xlsx");
// Get the first worksheet in the book.
Worksheet sheet = workbook.Worksheets[0];
// Insert 10 rows at row index 2 (insertion starts at 3rd row)
sheet.Cells.InsertRows(2, 10);
// Delete 5 rows now. (8th row - 12th row)
sheet.Cells.DeleteRows(7, 5);
// Save the excel file.
workbook.Save(dataDir+ "out_book1.out.xlsx");