範囲の削除
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") |