Exemplo n.º 1
0
def write_to_book(sheet: Worksheet, row: int, cur_inf: dict):
    """
    Запись обработанной информации в Worksheet.
    """
    row = sheet.row(row)
    style = XFStyle()
    for index, value in enumerate(cur_inf.values()):
        if (row != 0) and (index != 0 or 3):
            style.num_format_str = '"₽"#,##0.0000;"₽"#,##0.0000'
        sheet.col(index).width = 4000
        row.write(index, value, style=style)
Exemplo n.º 2
0
    def header(self, sheet: xlwt.Worksheet, name: str) -> None:
        """
        Write sheet header.

        :param sheet: instance of xlwt sheet to write header to
        :type sheet: xlwt.Worksheet
        :param name: sheet name
        :type name: str
        """
        header: xlwt.Row = sheet.row(0)

        for i, column in enumerate(  # pylint: disable=W0612  # noqa: B007
            self.HEADERS[name]
        ):
            header.write(i, self.HEADERS[name][i])

        sheet.flush_row_data()
Exemplo n.º 3
0
def write_old_xls(worksheet: xlwt.Worksheet, data, offset=0, ):
    style = xlwt.Style.easyxf(
        f"font: height 200, name 宋体; align: vert centre, horiz center, wrap 1; borders: left {xlwt.Borders.THIN},"
        f" right {xlwt.Borders.THIN}, top {xlwt.Borders.THIN}, bottom {xlwt.Borders.THIN}")
    for k, v in enumerate(data):
        k = k + offset
        height = 50
        for key, value in enumerate(v):
            width = worksheet.col(key).width
            if str(value).split(".")[-1].upper() in ["JPG", "JPEG", "PNG"]:
                value = value.replace(config["FILE"]["PATH"], config["FILE"]["IP"])
            if len(str(value)) * 200 > worksheet.col(key).width:
                width = len(value) * 200
            worksheet.col(key).width = width
            if "http" in str(value):
                value = xlwt.Formula(f'Hyperlink("{value}";"{value}")')
            worksheet.write(k, key, value, style=style)
        worksheet.row(k).height_mismatch = True
        worksheet.row(k).height = int(20 * height)