Home > database >  Openpyxl gets tricky
Openpyxl gets tricky

Time:05-30

There are multiple questions regarding Openpyxl once you try to implement it in your code.

what can be done to append multiple rows of data...
SS1
OR
SS2
do we save the file with every append or after all the appends??

I am doing this, it corrupts the excel file. I assume that the corruption occurs due to the indent at the end, I have no idea on what to do if that is not the case.


https://github.com/Seshrut/billing/blob/main/Main


the file was too big

CodePudding user response:

Edit to address added code

My guess is your issue is in this line

for row in range(2, 1048576):

which means the appends you are making;

ws.append([srNO, phno, name, d, m, H, M, billno, Art_ ...

are being added at row 1048577 and up.
Excel only has 1048576 rows in a sheet so the excel file will be corrupted when saved.
Are there that many phone numbers to be searched? You should set the range to cover only the rows that need to be searched. If this is variable you can check the number of rows in the column and set the upper range value each time the code is run.

CodePudding user response:

the first option is correct you shouldn't save the file each time you add a row saving once at the end is enough

  • Related