def get_rows_to_write(worksheet): """Return all rows, and any cells that they contain""" # Ensure a blank cell exists if it has a style for styleCoord in iterkeys(worksheet._styles): if isinstance(styleCoord, str) and COORD_RE.search(styleCoord): worksheet.cell(styleCoord) # create rows of cells cells_by_row = {} for cell in itervalues(worksheet._cells): cells_by_row.setdefault(cell.row, []).append(cell) # make sure rows that only have a height set are returned for row_idx in worksheet.row_dimensions: if row_idx not in cells_by_row: cells_by_row[row_idx] = [] return cells_by_row