Inserisci intervalli
Introduzione
In Excel, puoi selezionare un intervallo, quindi inserire un intervallo e spostare altri dati a destra o verso il basso.
Inserire Range Utilizzando la Libreria Excel Aspose.Cells for Python
Aspose.Cells for Python via .NET fornisce il metodo Cells.insert_range per inserire un range.
Come inserire range e spostare celle a destra
Inserisci un intervallo e sposta le celle a destra come nei seguenti codici con Aspose.Cells:
from aspose.cells import CellArea, ShiftType, Workbook | |
# Instantiate a new Workbook. | |
workbook = Workbook() | |
# Get all the worksheets in the book. | |
worksheets = workbook.worksheets | |
# Get the first worksheet in the worksheets collection. | |
worksheet = workbook.worksheets[0] | |
cells = worksheet.cells | |
# Create a range of cells. | |
sourceRange = cells.create_range("A1", "A2") | |
startRow = sourceRange.first_row | |
startCol = sourceRange.first_column | |
# Input some data with some formattings into | |
# A few cells in the range. | |
cells.get(startRow, startCol).put_value("Test") | |
cells.get(startRow + 1, startCol).put_value("123") | |
ca = CellArea.create_cell_area("A1", "A2") | |
worksheet.cells.insert_range(ca, ShiftType.RIGHT) | |
print(worksheet.cells.get("B1").string_value == "Test") |
Come Inserire Intervalli e Spostare le Celle in Basso
Inserisci un intervallo e sposta le celle verso il basso come nei seguenti codici con Aspose.Cells:
from aspose.cells import CellArea, ShiftType, Workbook | |
# Instantiate a new Workbook. | |
workbook = Workbook() | |
# Get all the worksheets in the book. | |
worksheets = workbook.worksheets | |
# Get the first worksheet in the worksheets collection. | |
worksheet = workbook.worksheets[0] | |
cells = worksheet.cells | |
# Create a range of cells. | |
sourceRange = cells.create_range("A1", "A2") | |
startRow = sourceRange.first_row | |
startCol = sourceRange.first_column | |
# Input some data with some formattings into | |
# A few cells in the range. | |
cells.get(startRow, startCol).put_value("Test") | |
cells.get(startRow + 1, startCol).put_value("123") | |
ca = CellArea.create_cell_area("A1", "A2") | |
worksheet.cells.insert_range(ca, ShiftType.DOWN) | |
print(worksheet.cells.get("A3").string_value == "Test") |