class spreadsheet(object): def __init__(self, name): self.name = name self.max_height = INITIAL_HEIGHT self.height = 0 self.sprsh = SodsSpreadSheet(i_max=self.height, j_max=COLUMNS) def __enter__(self): return self def __exit__(self, type, value, traceback): self.save() def add_row(self, data, status=STATUS_VALID, rank=None): # resize if necessary if self.height == self.max_height: self.max_height += 1000 self.sprsh.resizeTable(i_max=self.max_height) if len(data) != COLUMNS: raise Exception("Invalid data: expected " + str(COLUMNS) + " columns") row = self.height for col, field in enumerate(data): if field is None: field = "" coords = _encode_cell(row, col) self.sprsh.setValue(coords, field) if status == STATUS_VALID: try: styles = RANK_STYLES[rank] except KeyError: styles = RANK_STYLES[UNRANKED] self.sprsh.setStyle(coords, **styles) else: self.sprsh.setStyle(coords, **(STATUS_STYLES[status])) self.height += 1 def save(self): file_name = "export/" + self.name + ".ods" ods = SodsOds(self.sprsh) ods.save(file_name)
def __init__(self, name): self.name = name self.max_height = INITIAL_HEIGHT self.height = 0 self.sprsh = SodsSpreadSheet(i_max=self.height, j_max=COLUMNS)