Bereiche löschen
Einführung
In Excel können Sie einen Bereich auswählen, löschen und andere Daten links oder nach oben verschieben.
Löschen von Bereichen mit Aspose.Cells
Aspose.Cells bietet die Methode Cells.delete_range zum Löschen eines Bereichs.
Bereiche löschen und Zellen nach links verschieben
Löschen Sie einen Bereich und verschieben Sie Zellen nach links, wie in den folgenden Codes mit 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] | |
# Gets cells. | |
cells = worksheet.cells | |
# Input some data with some formattings into | |
# A few cells in the range. | |
cells.get("C2").put_value("C2") | |
cells.get("C3").put_value("C3") | |
ca = CellArea.create_cell_area("B2", "B3") | |
cells.delete_range(ca.start_row, ca.start_column, ca.end_row, ca.end_column, ShiftType.LEFT) | |
print(worksheet.cells.get("B2").string_value == "C2") |
Bereiche löschen und Zellen nach oben verschieben
Löschen Sie einen Bereich und verschieben Sie die Zellen nach oben wie in den folgenden Codes mit 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] | |
# Gets cells. | |
cells = worksheet.cells | |
# Input some data with some formattings into | |
# A few cells in the range. | |
cells.get("B4").put_value("B4") | |
cells.get("B5").put_value("B5") | |
ca = CellArea.create_cell_area("B2", "B3") | |
cells.delete_range(ca.start_row, ca.start_column, ca.end_row, ca.end_column, ShiftType.UP) | |
print(worksheet.cells.get("B2").string_value == "B4") |