範囲を挿入

序章

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

シフト オプション

Aspose.Cells を使用して範囲を挿入する

Aspose.Cells提供Cells.InsertRange範囲を挿入するメソッド。

範囲を挿入して Cells を右にシフト

範囲を挿入し、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");

範囲を挿入して Cells を下にシフト

範囲を挿入し、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");