def format_output(val,eachformat, eachstyle): "Returns a excel cell with the data formated as specified" new_cell = WriteOnlyCell(xls_sheet, value = "init") new_cell.style = eachstyle if val==None: val="None" elif eachformat == None: pass elif eachformat == "OLE": val = ole_timestamp(val) new_cell.number_format = 'YYYY MMM DD' elif eachformat.startswith("OLE:"): val = ole_timestamp(val) val = val.strftime(eachformat[4:]) elif eachformat=="FILE": val = file_timestamp(val) new_cell.number_format = 'YYYY MMM DD' elif eachformat.startswith("FILE:"): val = file_timestamp(val) val = val.strftime(eachformat[5:]) elif eachformat.lower() == "lookup_id": val = id_table.get(val, "No match in srum lookup table for %s" % (val)) elif eachformat.lower() == "lookup_luid": val = lookup_luid(val) elif eachformat.lower() == "lookup_sid": val = "%s (%s)" % (val, lookup_sid(val)) elif eachformat.lower() == "seconds": val = val/86400.0 new_cell.number_format = 'dd hh:mm:ss' elif eachformat.lower() == "md5": val = hashlib.md5(str(val)).hexdigest() elif eachformat.lower() == "sha1": val = hashlib.sha1(str(val)).hexdigest() elif eachformat.lower() == "sha256": val = hashlib.sha256(str(val)).hexdigest() elif eachformat.lower() == "base16": if type(val)=="<type 'int'>": val = hex(val) else: val = str(val).encode("hex") elif eachformat.lower() == "base2": if type(val)==int: val = bin(val) else: try: val = int(str(val),2) except : val = val new_cell.comment = Comment("Warning: Unable to convert value %s to binary." % (val),"srum_dump") elif eachformat.lower() == "interface_id" and options.reghive: val = interface_table.get(str(val),"") elif eachformat.lower() == "interface_id" and not options.reghive: val = val new_cell.comment = Comment("WARNING: Ignoring interface_id format command because the --REG_HIVE was not specified.", "srum_dump") else: val = val new_cell.comment = Comment("WARNING: I'm not sure what to do with the format command %s. It was ignored." % (eachformat), "srum_dump") new_cell.value = val return new_cell
def fill_cell(working_sheet, value, negrita=False): # TODO add colors depending on the day (labor or not) try: cell = WriteOnlyCell(working_sheet, value=value) cell.style = Style( font=Font(name="Calibri", size=11, bold=negrita), border=Border( left=Side(border_style=borders.BORDER_THIN, color="FF000000"), right=Side(border_style=borders.BORDER_THIN, color="FF000000"), top=Side(border_style=borders.BORDER_THIN, color="FF000000"), bottom=Side(border_style=borders.BORDER_THIN, color="FF000000"), ), ) cell.alignment = Alignment(horizontal="center", vertical="center") except: pass return cell
print "\nCreating Sheet " + each_sheet if not options.quiet: try: ad = ads.next() except: ad = "Thanks for using srum_dump!" print "While you wait, did you know ...\n" + ad + "\n" xls_sheet = target_wb.create_sheet(title=each_sheet) #Now copy the header values and header formats from the template to the new worksheet header_row = [] for eachcolumn in range(1, len(ese_template_fields) + 1): cell_value = template_sheet.cell(row=4, column=eachcolumn).value cell_style = template_sheet.cell(row=4, column=eachcolumn).style new_cell = WriteOnlyCell(xls_sheet, value=cell_value) new_cell.style = cell_style header_row.append(new_cell) xls_sheet.append(header_row) #Until we get an empty row retrieve the rows from the ESE table and process them row_num = 1 #Init to 1, first row will be 2 in spreadsheet (1 is headers) while True: try: ese_row = ese_db.getNextRow(ese_table) except Exception as e: print "Skipping corrupt row in the %s table. The last good row was %s." % ( each_sheet, row_num) continue if ese_row == None: break #The row is retrieved now use the template to figure out which ones you want and format them xls_row = []