範囲内のデータを検索および置換する

可能な使用シナリオ

特定の範囲内のデータを検索および置換する必要がある場合もあります。Aspose.Cells for Python via .NETを使用すると、特定の範囲で検索を制限できます。この記事では、Pythonコードを使用してExcelで範囲内のデータを検索および置換する方法について説明しています。

Aspose.Cells for Python Excelライブラリを使用した範囲内のデータの検索および置換方法

Python via .NETを使用してデータを検索する場合の範囲の指定には、FindOptions.set_range()メソッドが提供されています。以下のコードサンプルは、範囲内でデータを検索および置換します。

from aspose.cells import CellArea, FindOptions, LookAtType, LookInType, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
filePath = dataDir + "input.xlsx"
workbook = Workbook(filePath)
worksheet = workbook.worksheets[0]
# Specify the range where you want to search
# Here the range is E3:H6
area = CellArea.create_cell_area("E9", "H15")
# Specify Find options
opts = FindOptions()
opts.look_in_type = LookInType.VALUES
opts.look_at_type = LookAtType.ENTIRE_CONTENT
opts.set_range(area)
cell = None
while True:
cell = worksheet.cells.find("search", cell, opts)
if cell:
cell.put_value("replace")
else:
break
# Save the workbook
workbook.save(dataDir + "output.out.xlsx")