Insertar Rangos
Introducción
En Excel, puedes seleccionar un rango, luego insertar un rango y desplazar otros datos hacia la derecha o hacia abajo.
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.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"); | |
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.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"); | |