I've poured over numerous versions of this same question, but simply cannot find a working solution for looping through a group of cells and checking for empty ones.
Here's my code:
wb = openpyxl.Workbook(write_only=False)
sheet = wb.get_sheet_by_name('Sheet')
for i in range(1, 20):
if sheet.cell(row=i, column=1).value == None or 'None':
print('Space' + str(i))
sheet.cell(row=i, column=1) = i
else:
pass
wb.save('filename.xlsx')
But for some reason it writes to the empty cells AND overwrites the cells which had values written in them.
I comment out the loop I find that if I run the code it erases everything that was manually written into the spreadsheet to begin with. Maybe that's part of the problem?
Also I'm using LibreOffice if that makes a difference
Truewhich is why you overwrite existing cells. - Charlie Clark