範囲の挿入

紹介

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.getWorksheets();
// Get the first worksheet in the worksheets collection.
Worksheet worksheet = workbook.getWorksheets().get(0);
// Create a range of cells.
Range sourceRange = worksheet.getCells().createRange("A1", "A2");
// Set a few cells in the range.
sourceRange.get(0, 0).putValue("Test");
sourceRange.get(1, 0).putValue("123");
CellArea ca = CellArea.createCellArea("A1", "A2");
worksheet.getCells().insertRange(ca, ShiftType.RIGHT);
String b1Value = worksheet.getCells().get("B1").getStringValue();// "Test"

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

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

// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Get all the worksheets in the book.
WorksheetCollection worksheets = workbook.getWorksheets();
// Get the first worksheet in the worksheets collection.
Worksheet worksheet = workbook.getWorksheets().get(0);
// Create a range of cells.
Range sourceRange = worksheet.getCells().createRange("A1", "A2");
// Set a few cells in the range.
sourceRange.get(0, 0).putValue("Test");
sourceRange.get(1, 0).putValue("123");
CellArea ca = CellArea.createCellArea("A1", "A2");
worksheet.getCells().insertRange(ca, ShiftType.DOWN);
String a3Value = worksheet.getCells().get("A3").getStringValue();// "Test"