Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access cell values faster with openpyxl?

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?

like image 807
ndemir Avatar asked Jul 29 '11 08:07

ndemir


2 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.

like image 59
Eric Gazoni Avatar answered Sep 27 '22 20:09

Eric Gazoni


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

for row in sheet.rows:
    for cell in row:
        print cell.value
like image 42
Snakes and Coffee Avatar answered Sep 27 '22 19:09

Snakes and Coffee