Skip to main content
1 of 2
Janne Karila
  • 10.4k
  • 20
  • 34

To make it faster you could move this

(cols for cols in range(self.sheet.ncols) if cols not in self.col_indexes_to_delete)

out of the loop, and use enumerate instead of explicitly incrementing variables.

Revised code:

def write_workbook_to_file(self, dstfilename):
    self.populaterownumstodelete()
    rows = [row for row in xrange(self.sheet.nrows) if row not in self.row_nums_to_delete]
    cols = [col for col in xrange(self.sheet.ncols) if col not in self.col_indexes_to_delete]
    for row_write, row in enumerate(rows):
        for col_write, col in enumerate(cols):
            self.wb_sheet.write(row_write, col_write, self.parseandgetcellvalue(row, col))
Janne Karila
  • 10.4k
  • 20
  • 34