Пример #1
0
def test_row_height(worksheet, write_rows):
    from openpyxl.worksheet.dimensions import RowDimension
    ws = worksheet
    ws['F1'] = 10
    ws.row_dimensions[1] = RowDimension(ws, height=30)
    ws.row_dimensions[2] = RowDimension(ws, height=30)

    out = BytesIO()
    with xmlfile(out) as xf:
        write_rows(xf, ws)
    xml = out.getvalue()
    expected = """
     <sheetData>
       <row customHeight="1" ht="30" r="1" spans="1:6">
         <c r="F1" t="n">
           <v>10</v>
         </c>
       </row>
       <row customHeight="1" ht="30" r="2" spans="1:6"></row>
     </sheetData>
    """
    diff = compare_xml(xml, expected)
    assert diff is None, diff
Пример #2
0
    def parse_row(self, row):
        attrs = dict(row.attrib)

        if "r" in attrs:
            self._row_count = int(attrs['r'])
        else:
            self._row_count += 1
        self._col_count = 0
        keys = set(attrs)
        for key in keys:
            if key == "s":
                attrs['s'] = self.styles[int(attrs['s'])]
            elif key.startswith('{'):
                del attrs[key]

        keys = set(attrs)
        if keys != set(['r', 'spans']) and keys != set(['r']):
            # don't create dimension objects unless they have relevant information
            dim = RowDimension(self.ws, **attrs)
            self.ws.row_dimensions[dim.index] = dim

        for cell in safe_iterator(row, self.CELL_TAG):
            self.parse_cell(cell)
Пример #3
0
 def bind_row_dimensions(self):
     for row, rd in self.parser.row_dimensions.items():
         if 's' in rd:
             key = int(rd['s'])
             rd['s'] = self.ws.parent._cell_styles[key]
         self.ws.row_dimensions[int(row)] = RowDimension(self.ws, **rd)
Пример #4
0
def xl_set_row_height(sheet, row, cm):
    """ change row height """
    if row not in sheet.row_dimensions.keys():
        sheet.row_dimensions[row] = RowDimension(worksheet=sheet)
    sheet.row_dimensions[row].height = xl_row_height(cm)
Пример #5
0
    def _get_obracun_plate(self):
        wb = openpyxl.Workbook(encoding='utf-8')
        ws = wb.create_sheet(0, self.employee_id.name)

        for i in range(1, 30):
            for j in range(1, 10):
                ws.cell(row=i, column=j).alignment.vertical = "center"
                ws.cell(row=i, column=j).alignment.horizontal = "center"

        ws['D5'] = 'ZARADA ZA MJESEC ' + dict(MONTHS).get(self.month).upper() + ' ' + dict(YEARS).get(
            self.year).upper() + '. GODINE'
        ws['D5'].font = Font(bold=True)

        ws['B7'] = "Vozac: " + self.employee_id.name
        ws['B7'].font = Font(bold=True)
        # ws['B7'].style.alignment = Alignment(horizontal="center", vertical="center", wrapText=True)

        ws['B8'] = 'R. br.'
        ws['B8'].font = Font(bold=True)
        ws['B8'].border = Border(left=Side(style='thick'), top=Side(style='thick'), bottom=Side(style='thick'))
        # ws['B8'].style.alignment = Alignment(horizontal="center", vertical="center", wrapText=True)

        ws['C8'] = 'Br. koverte'
        ws['C8'].font = Font(bold=True)
        ws['C8'].border = Border(bottom=Side(style='thick'), top=Side(style='thick'))
        # ws['C8'].style.alignment = Alignment(horizontal="center", vertical="center", wrapText=True)

        ws['D8'] = 'Datum'
        ws['D8'].font = Font(bold=True)
        ws['D8'].border = Border(bottom=Side(style='thick'), top=Side(style='thick'))
        # ws['D8'].style.alignment = Alignment(horizontal="center", vertical="center", wrapText=True)

        ws['E8'] = 'Br. fakture'
        ws['E8'].font = Font(bold=True)
        ws['E8'].border = Border(top=Side(style='thick'))
        # ws['E8'].style.alignment = Alignment(horizontal="center", vertical="center", wrapText=True)

        ws['F8'] = 'Relacija'
        ws['F8'].font = Font(bold=True)
        ws['F8'].border = Border(top=Side(style='thick'))
        # ws['F8'].style.alignment = Alignment(horizontal="center", vertical="center", wrapText=True)

        ws['G8'] = 'Količina\n(tona)'
        ws['G8'].font = Font(bold=True)
        # ws['G8'].style.alignment = Alignment(horizontal="center", vertical="center", wrapText=True)
        ws['G8'].border = Border(top=Side(style='thick'))

        ws['H8'] = 'Cijena\n€/Toni'
        ws['H8'].font = Font(bold=True)
        ws['H8'].border = Border(top=Side(style='thick'))
        # ws['H8'].style.alignment = Alignment(horizontal="center", vertical="center", wrapText=True)

        ws['I8'] = 'Vrijednost\n€'
        ws['I8'].font = Font(bold=True)
        ws['I8'].border = Border(top=Side(style='thick'))
        # ws['I8'].style.alignment = Alignment(horizontal="center", vertical="center", wrapText=True)

        ws['J8'] = 'Vrjednost\nKM'
        ws['J8'].font = Font(bold=True)
        ws['J8'].border = Border(top=Side(style='thick'))
        # ws['J8'].style.alignment = Alignment(horizontal="center", vertical="center", wrapText=True)

        ws['K8'] = 'Zarada vozača'
        ws['K8'].font = Font(bold=True)
        ws['K8'].border = Border(right=Side(style='thick'), top=Side(style='thick'))
        # ws['K8'].style.alignment = Alignment(horizontal="center", vertical="center", wrapText=True)

        ws.row_dimensions[8] = RowDimension(worksheet=ws, height=40)
        ws.column_dimensions['F'] = ColumnDimension(worksheet=ws, width=40)
        ws.column_dimensions['I'] = ColumnDimension(worksheet=ws, width=12)
        ws.column_dimensions['J'] = ColumnDimension(worksheet=ws, width=12)

        buf = cStringIO.StringIO()
        wb.save(buf)
        buf.seek(0)
        out = base64.encodestring(buf.read())
        buf.close()

        self.data = out
        self.name = "obracun_plate.xlsx"  # +self.employee_id.name+"_"+dict(MONTHS).get(self.month)+"_"+dict(YEARS).get(self.year)
        self.state = 'get'
        return True