插入范围
Contents
[
Hide
]
介绍
在 Excel 中,您可以选择一个范围,然后插入一个范围,并向右或向下移动其他数据。
使用Aspose.Cells for Python Excel库插入范围
Aspose.Cells for Python via .NET 提供 Cells.insert_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] | |
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") |
如何插入范围并向下移动单元格
插入一个范围,并像下面的 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] | |
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") |