Insertar Rangos

Introducción

En Excel, puedes seleccionar un rango, luego insertar un rango y desplazar otros datos hacia la derecha o hacia abajo.

Opciones de desplazamiento

Insertar Rangos Usando Aspose.Cells

Aspose.Cells proporciona el método Cells.InsertRange para insertar un rango.

Insertar Rangos y Desplazar Celdas a la Derecha

Insertar un rango y desplazar celdas a la derecha como los siguientes códigos con 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"

Insertar Rangos y Desplazar Celdas hacia Abajo

Inserte un rango y desplace las celdas hacia abajo como los siguientes códigos con 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"