Удалить диапазоны
Contents
[
Hide
]
Введение
В Excel можно выбрать диапазон, затем удалить его и сдвинуть другие данные влево или вверх.
Удаление диапазонов с помощью Aspose.Cells
Aspose.Cells предоставляет метод Cells.delete_range для удаления диапазона.
Удалить диапазоны и сдвинуть ячейки влево
Удалить диапазон и сдвинуть ячейки влево с помощью следующих кодов с Aspose.Cells:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Удалить диапазоны и сдвинуть ячейки вверх
Удалить диапазон и сдвинуть ячейки вверх с помощью следующих кодов с Aspose.Cells:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |