I've been working on a project, in which I search an .xlsx document for a cell containing a specific value "D", and then insert a blank row before the row of that cell
Here's the example code I have come up with:
import openpyxl
wb = openpyxl.load_workbook('TestFile4.xlsx')
sheet = wb['Sheet1']
for row in sheet.iter_rows():
for cell in row:
if cell.value == 'D':
sheet.insert_rows(cell.row, amount=1)
When I run this script, instead of inserting one row before the row of the cell has value 'D', it inserted 5 rows like this: https://i.stack.imgur.com/saSWf.png
Can you help me? Thanks so much!