删除范围
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") |