Excel ワークシートでの行の挿入または削除
Contents
[
Hide
]
新しいワークシートを作成するとき、または既存のワークシートを操作するときに、データを格納するために余分な行または列を追加する必要がある場合があります。また、ワークシートの指定した位置から行または列を削除する必要がある場合もあります。
Aspose.Cells は、行を挿入および削除するための 2 つの方法を提供します。Cells.InsertRowsとCells.DeleteRows.これらのメソッドは、パフォーマンスのために最適化されており、ジョブを非常に迅速に実行します。
複数の行を挿入または削除するには、常にCells.InsertRowsとCells.DeleteRowsメソッドを使用する代わりにCells.InsertRowまた行の削除ループ内のメソッド。
Aspose.Cells は、Microsoft Excel と同じように機能します。行または列が追加されると、ワークシートの内容が右下に移動します。行または列が削除されると、ワークシートの内容が上または左に移動します。行が追加または削除されると、他のワークシートおよびセル内のすべての参照が更新されます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |