範囲の挿入

紹介

Excelでは、範囲を選択し、その後、他のデータを右または下にシフトして範囲を挿入できます。

! 挿入オプション

Aspose.Cellsを使用した範囲の挿入

Aspose.CellsはCells.InsertRangeメソッドを使用して範囲を挿入します。

範囲の挿入とセルの右シフト

Aspose.Cellsを使用して範囲を挿入し、セルを右にシフトする方法は次のコードの通りです:

// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Get all the worksheets in the book.
WorksheetCollection worksheets = workbook.Worksheets;
// Get the first worksheet in the worksheets collection.
Worksheet worksheet = workbook.Worksheets[0];
// Create a range of cells.
Range sourceRange = worksheet.Cells.CreateRange("A1", "A2");
// Input some data with some formattings into
// A few cells in the range.
sourceRange[0, 0].PutValue("Test");
sourceRange[1, 0].PutValue("123");
CellArea ca = CellArea.CreateCellArea("A1", "A2");
worksheet.Cells.InsertRange(ca, ShiftType.Right);
Console.WriteLine(worksheet.Cells["B1"].StringValue == "Test");

範囲の挿入とセルの下シフト

Aspose.Cellsを使用して範囲を挿入し、セルを下にシフトする方法は次のコードの通りです:

// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Get all the worksheets in the book.
WorksheetCollection worksheets = workbook.Worksheets;
// Get the first worksheet in the worksheets collection.
Worksheet worksheet = workbook.Worksheets[0];
// Create a range of cells.
Range sourceRange = worksheet.Cells.CreateRange("A1", "A2");
// Input some data with some formattings into
// A few cells in the range.
sourceRange[0, 0].PutValue("Test");
sourceRange[1, 0].PutValue("123");
CellArea ca = CellArea.CreateCellArea("A1", "A2");
worksheet.Cells.InsertRange(ca, ShiftType.Down);
Console.WriteLine(worksheet.Cells["A3"].StringValue == "Test");