79623389

Date: 2025-05-15 13:10:33
Score: 0.5
Natty:
Report link

You can access rows separately and apply a replace only to each row, respectively:

workbook = Workbook('test.xlsx')

def replace_in_row(worksheet, row, old_value, new_value):
    for cell in worksheet.getCells().getRows().get(row):
        if old_value in str(cell.getValue()):
            cell.setValue(str(cell.getValue()).replace(old_value, new_value))

worksheet = workbook.getWorksheets().get(0)
replace_in_row(worksheet, 0, "one", "two")
replace_in_row(worksheet, 9, "one", "five")

or alternatively - adding to @MahrezBenHamad's answer - determine the column range and

max_column = worksheet.getCells().getMaxColumn()

worksheet.getCells().replace("one", "two", ReplaceOptions(), CellArea(0, 0, 0, max_column))
worksheet.getCells().replace("one", "five", ReplaceOptions(), CellArea(9, 0, 9, max_column))
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @MahrezBenHamad's
  • Low reputation (0.5):
Posted by: André