Python Forum
How can I speed up my openpyxl program reading Excel .xlsx files?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I speed up my openpyxl program reading Excel .xlsx files?
#1
Like many folks I need to read both .xls files (I call them S files, using xlrd) and .xlsx files (the X files, using openpyxl), in both cases files of about 30,000 rows. And in both cases I'm just copying all excel data read out to a .csv file, no other processing so just Input/Output.

But the X file operations are over 200 times slower than for .xls, for example reading a 30,000 row .xlsx file now takes 2 minutes compared to 1/2 second for .xls with xlrd. We have thousands of files to process so the time per file matters.

Is openpyxl that much slower or do I need to do something, like release some resource at the end of each row?

BTW, I have made several great improvements by using read_only=True and reading a row at a time instead of cell by cell
as shown in the following code segment. Thanks to blog.davep.org
https://blog.davep.org/2018/06/02/a_litt...npyxl.html


	wb = openpyxl.load_workbook("excel_file.xlsx",  data_only=True,  read_only=True)
	sheet = wb.active
	for row in sheet.rows:
	    for cell in row:
	        cell_from_excel = cell.value
Reply


Messages In This Thread
How can I speed up my openpyxl program reading Excel .xlsx files? - by deac33 - May-04-2020, 08:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy Paste excel files based on the first letters of the file name Viento 2 427 Feb-07-2024, 12:24 PM
Last Post: Viento
  trouble reading string/module from excel as a list popular_dog 0 418 Oct-04-2023, 01:07 PM
Last Post: popular_dog
  Excel Automation using Openpyxl pradyumnajpn 1 804 May-16-2023, 09:38 AM
Last Post: Larz60+
  .py pandas matplotlib .xlsx files QubeStory 1 790 Mar-23-2023, 09:38 AM
Last Post: buran
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,092 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Excel file reading problem max70990 1 895 Dec-11-2022, 07:00 PM
Last Post: deanhystad
  How to loop through all excel files and sheets in folder jadelola 1 4,462 Dec-01-2022, 06:12 PM
Last Post: deanhystad
  Openpyxl manipulate excel write formula SamLiu 0 1,053 Nov-04-2022, 03:00 PM
Last Post: SamLiu
  Creating csv files from Excel file azizrasul 40 5,586 Nov-03-2022, 08:33 PM
Last Post: azizrasul
  [split] Results of this program in an excel file eisamabodian 1 1,575 Feb-11-2022, 03:18 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020