简体   繁体   中英

Copying data in excel - openpyxl

I use the code fragment below to copy data to an excel file using openpyxl.

      for i, j in enumerate(fint):
       _= ws1.cell(column=i +1, row=globdat.cycle, value=j)

   wb.save(filename = dest_filename)

BUT

after doing so I have found the code to become very slow. is there a better way of doing this ?

globdat.cycle is a count for each iteration.

'fint' is a row vector with an unknown number of entries in each iteration.

Nb- I am working with large amounts of data so only openpyxl seem to work.

Unfortunately, due to the way data is stored in Excel it's quite difficult to do copy operations. The xlutils library does include some functions designed specifically for this but I don't know if they work for xlsx files.

If you just want part of the data then I would suggest that you open the file to copy from in read-only mode and write to another one in write-only mode. This will keep memory use down and should be pretty fast.

For other situations there were some suggestions made on the bug tracker: https://bitbucket.org/openpyxl/openpyxl/issue/171/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM