Home » excel » python – how to access cell values faster with openpyxl?

python – how to access cell values faster with openpyxl?

Posted by: admin March 9, 2020 Leave a comment

Questions:
for rownum in range(0, len(self.sheet.rows) ):
   for cell in self.sheet.rows[rownum]:
      print cell.value

I want to access all cell values in a sheet row by row with openpyxl. Above code works but too slow. How can I access all cell values faster?

How to&Answers:

If you’re only reading cells from top to bottom and from left to right (like most of us) you can use the “optimized reader” http://openpyxl.readthedocs.org/en/latest/optimized.html. It works quite fast (CPU bound) and has smaller memory footprint than regular reader.

Disclaimer: I’m the author of openpyxl.

Answer:

Just hazarding a guess, I think this might be faster.

for row in sheet.rows:
    for cell in row:
        print cell.value