Ejemplo n.º 1
0
    def convert(self, infile, outfile):
        WidthsDumpWorksheet.col_widths = {}

        for width_spec in self.args.col_width or ():
            col, width = width_spec.split(',', 1)
            if '-' in col:
                col_lo, col_hi = map(column_index_from_string, col.split('-', 1))
            else:
                col_lo = col_hi = column_index_from_string(col)

            WidthsDumpWorksheet.col_widths[(col_lo, col_hi)] = width

        # TODO: This will be used when we switch to openpyxl 2.1.
        #Workbook._optimized_worksheet_class = WidthsDumpWorksheet

        wb = Workbook(optimized_write=True, optimized_worksheet_class=WidthsDumpWorksheet)

        ws = wb.create_sheet(title=self.args.sheet_name)

        for row in self.iter_rows(self.get_reader(infile)):
            ws.append(row)

        wb.save(outfile)

        # Clean up the mess.
        WidthsDumpWorksheet.col_widths = {}
Ejemplo n.º 2
0
    def __init__(self):
        self.args = self.parse_args()

        self.integer_cols = [column_index_from_string(c)-1 for c in self.args.integer_cols.split(',')]\
            if self.args.integer_cols else []

        def datetime_spec_parse(arg_tuple):
            str_col, in_format, out_format = arg_tuple.split(';', 2)
            out_cell = {'style': Style(number_format=numbers.NumberFormat(format_code=out_format))}
            return column_index_from_string(str_col)-1, (in_format, out_cell)

        self.datetime_spec_dict = dict(datetime_spec_parse(a) for a in self.args.datetime_spec or ())

        self.HEADER_STYLE = Style(font=Font(bold=True))
        self.strptime = datetime.datetime.strptime
Ejemplo n.º 3
0
	col = 0
	while cell0.offset(0, col+1).value != None and cell0.offset(0, col+1).value != "":
	    col = col+1

	row = 0
	while cell0.offset(row+1, 0).value != None and cell0.offset(row+1, 0).value != "":
	    row = row+1

	cells.append(cell0.offset(row, col).coordinate)

    else:
	cell0 = ws[cells[0]]
	cell1 = ws[cells[1]]

	col = column_index_from_string(cell1.column)


    print "source	", file, "	", sheet, "	", "\t".join(cells)
    print ""

    if header:
	header = []
	dashes = []
	for row in ws.range(cell0.coordinate + ":" + cell0.offset(0, col).coordinate):
	    for cell in row:
		name = re.sub('[^a-zA-Z0-9_]', "", str(cell.value)).strip()

		header.append(          name)
		dashes.append("-" * len(name))
Ejemplo n.º 4
0
 def datetime_spec_parse(arg_tuple):
     str_col, in_format, out_format = arg_tuple.split(';', 2)
     out_cell = {'style': Style(number_format=numbers.NumberFormat(format_code=out_format))}
     return column_index_from_string(str_col)-1, (in_format, out_cell)