Write to a new, modified Excel file from an original one I noticed that I've a HUGE bottleneck in this following function of mine. I can't see how to make it faster.

These are the profiling test results(keep in mind that I'm using a PyQt GUI so times can be stretched):

cProfile Results

def write_workbook_to_file(self, dstfilename):
    self.populaterownumstodelete()
    # actual column in the new file
    col_write = 0
    # actual row in the new file
    row_write = 0
    for row in (rows for rows in range(self.sheet.nrows) if rows not in self.row_nums_to_delete):
        for col in (cols for cols in range(self.sheet.ncols) if cols not in self.col_indexes_to_delete):
            self.wb_sheet.write(row_write, col_write, self.parseandgetcellvalue(row, col))
            col_write += 1
        row_write += 1
        col_write = 0


I ran a cProfile profiling test and write_workbook_to_file() resulted the slowest function in all my application. parseandgetcellvalue() isn't a problem at all.
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))


In fact you could even move enumerate out of the loop, but I like how the code looks quite clean now.