範囲の挿入
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") |