I can't wrap the logic around my head. Can someone suggest a solution.
I have an excel file with 10000 items in row A of worksheet0 I want to iterate over the rows, but in groups of 200. Here is my dry algorithm that I can't seem to put into code:
read an excel file, worksheet0 as source
create an empty excel worksheet using openpyxl, worksheet1
itereate over the first 200 string items of 10000 total in column A from source worksheet0
a. strip() each string item b. save the 'stripped' new strings in worksheet1 columnA, row1:row200
- create a new empty worksheet, worksheet2
- iterate over the next 200 string items from worksheet0 row201:400 a. strip() b. save in worksheet2
repeat this creation of new worksheet, stripping and saving in this new worksheet for every group of 200
I just can't get the algorithm to iterate over groups of 200 and every new group create a new worksheet file. Can anyone help with the algo?
# rowMax is the last row in columnA aka the length of my list to iterate over
for count in range(1, int(rowMax/200)):
_=wb.create_sheet(str(count))
for row in range(count*2, 200*count):
targetEmail = str(ws1.cell(column=1, row=row).value).strip()
sourceEmail = str(ws1.cell(column=1, row=row).value)
if targetEmail != sourceEmail:
print("Correction required for: ", sourceEmail, "\nChanged to: ", targetEmail)
_.cell(column=1, row=row).value = targetEmail
The above doesn't work. I'm just putting it there so you understand that every 200 items I create a new worksheet and then save the next 200 items in that new worksheet, and then repeat this process for each 200 item chunk