Exemple #1
0
def txt_to_xls(txt_file):
    with open(txt_file, 'r') as f:
        file_content = json.load(f, encoding='utf-8')
        xls_workbook = xlwt3.Workbook(encoding='utf-8')
        xls_sheet = xls_workbook.add_sheet('student')
        style = xlwt3.XFStyle()
        font = xlwt3.Font()
        font.name = '黑体'
        style.font = font
        for i in range(len(file_content)):
            # 写入对应列号
            xls_sheet.write(i, 0, i + 1, style)
            json_data = file_content[str(i + 1)]
            for j in range(len(json_data)):
                xls_sheet.write(i, j + 1, json_data[j], style)
        xls_workbook.save('student.xls')
def txt_to_xls(txt_file):
    with open(txt_file, 'r') as f:
        # print(f)
        file_content = json.load(f)
        print(file_content)
        print(file_content[0])
        xls_workbook = xlwt3.Workbook()
        xls_sheet = xls_workbook.add_sheet('numbers')
        style = xlwt3.XFStyle()
        font = xlwt3.Font()
        font.name = '黑体'
        style.font = font
        for i in range(len(file_content)):
            for j in range(len(file_content[i])):
                xls_sheet.write(i, j, file_content[i][j])
        xls_workbook.save('numbers.xls')
Exemple #3
0
def txt_to_xls(txt_file):
    with open(txt_file, 'r') as f:
        # print(f)
        file_content = json.load(f)
        # print(file_content)
        xls_workbook = xlwt3.Workbook()
        xls_sheet = xls_workbook.add_sheet('city')
        style = xlwt3.XFStyle()
        font = xlwt3.Font()
        font.name = '黑体'
        style.font = font
        for i in range(len(file_content)):
            # 写入对应列号
            xls_sheet.write(i, 0, i + 1, style)
            json_data = file_content[str(i + 1)]
            print(json_data)
            xls_sheet.write(i, 1, json_data)
        xls_workbook.save('city.xls')
    def create_simple_xls(self):
        font0 = xlwt.Font()
        font0.name = 'Times New Roman'
        font0.colour_index = 2
        font0.bold = True

        style0 = xlwt.XFStyle()
        style0.font = font0

        style1 = xlwt.XFStyle()
        style1.num_format_str = 'D-MMM-YY'

        wb = xlwt.Workbook()
        ws = wb.add_sheet('A Test Sheet')

        ws.write(0, 0, 'Test', style0)
        ws.write(1, 0, datetime(2010, 12, 5), style1)
        ws.write(2, 0, 1)
        ws.write(2, 1, 1)
        ws.write(2, 2, xlwt.Formula("A3+B3"))

        wb.save('simple.xls')
Exemple #5
0
def print_from_db(collections):
    file_name = "excel_" + datetime.datetime.now().strftime(
        "%Y-%m-%d_%H%M%S") + ".xls"
    wb = xlwt.Workbook()
    ws = wb.add_sheet('0')
    # headers = ['п/н', 'Название', 'Дата', 'Ссылка', 'Начальная цена контракта',
    #     'Размер обеспечения', 'Несколько заказчиков', 'Победитель', 'Кол-во, ссылка',
    #     'Регион', 'Город', 'Телефон', 'ИНН', 'КПП', 'ОГРН']
    headers = [
        'п/н', 'Название', 'Дата', 'Ссылка', 'Начальная цена контракта',
        'Размер обеспечения', 'Несколько заказчиков', 'Победитель', 'Ссылка',
        'Регион', 'Телефон'
    ]
    ezxf = xlwt.easyxf
    font0, font1, font2, font3 = xlwt.Font(), xlwt.Font(), xlwt.Font(
    ), xlwt.Font()
    style0, style1, style2, style3 = xlwt.XFStyle(), xlwt.XFStyle(
    ), xlwt.XFStyle(), xlwt.XFStyle()

    style4 = ezxf("align: wrap on, vert centre, horiz left")

    font0.name = 'Times New Roman'
    font0.bold = True
    style0.font = font0

    font1.bold = False
    style1.font = font1
    style1.num_format_str = '# ### ##0.00'

    font2.colour_index = 4
    style2.font = font2

    style3.num_format_str = "DD.MM.YYYY"
    style3.font = font3

    col, row = 0, 0
    for head in headers:
        ws.write(row, col, head, style0)
        col += 1
    n = "HYPERLINK"
    row += 1
    for dt in collections:
        col = 0
        ws.write(row, col, row)
        col += 1
        ws.write(row, col, dt['name'], style4)
        col += 1
        ws.write(row, col, dt['date'], style3)
        col += 1
        ws.write(row, col,
                 xlwt.Formula(n + '("{0}";"{1}")'.format(dt['url'], dt['id'])),
                 style2)
        col += 1
        ws.write(row, col, dt['maxsum'], style1)
        col += 1
        ws.write(row, col, dt['garantsum'], style1)
        col += 1
        ws.write(row, col, dt['garantmix'])
        col += 1
        ws.write(row, col, dt['winner'], style4)
        col += 1
        ws.write(
            row, col,
            xlwt.Formula(n + '("{0}";"{1}")'.format(dt['surls'], dt['sname'])),
            style2)
        col += 1
        ws.write(row, col, dt['region'])
        col += 1
        # ws.write(row, col, dt['city'])
        # col += 1
        ws.write(row, col, dt['phone'])
        col += 1
        # ws.write(row, col, dt['inn'])
        # col += 1
        # ws.write(row, col, dt['kpp'])
        # col += 1
        # ws.write(row, col, dt['ogrn'])
        row += 1
    wb.save(file_name)
    return 0
Exemple #6
0
def print_result_col(collections=None):
    file_name = "excel_" + datetime.datetime.now().strftime(
        "%Y-%m-%d_%H%M%S") + ".xls"
    wb = xlwt.Workbook()
    ws = wb.add_sheet('0')
    headers = [
        'п/н', 'Название', 'Дата', 'Ссылка', 'Начальная цена контракта',
        'Размер обеспечения', 'Несколько заказчиков', 'Победитель',
        'Кол-во, ссылка', 'Регион', 'Город', 'Телефон', 'ИНН', 'КПП', 'ОГРН'
    ]
    ezxf = xlwt.easyxf
    font0, font1, font2, font3 = xlwt.Font(), xlwt.Font(), xlwt.Font(
    ), xlwt.Font()
    style0, style1, style2, style3 = xlwt.XFStyle(), xlwt.XFStyle(
    ), xlwt.XFStyle(), xlwt.XFStyle()

    style4 = ezxf("align: wrap on, vert centre, horiz left")

    font0.name = 'Times New Roman'
    font0.bold = True
    style0.font = font0

    font1.bold = False
    style1.font = font1
    style1.num_format_str = '# ### ##0.00'

    font2.colour_index = 4
    style2.font = font2

    style3.num_format_str = "DD.MM.YYYY"
    style3.font = font3

    col, row = 0, 0
    for head in headers:
        ws.write(row, col, head, style0)
        col += 1
    n = "HYPERLINK"
    row += 1
    for colecttion in collections:
        col = 0
        ws.write(row, col, row)
        col += 1
        ws.write(row, col, colecttion.name, style4)
        col += 1
        ws.write(row, col, colecttion.date, style3)
        col += 1
        ws.write(
            row, col,
            xlwt.Formula(
                n + '("{0}";"{1}")'.format(colecttion.url, colecttion.id)),
            style2)
        col += 1
        ws.write(row, col, colecttion.maxsum, style1)
        col += 1
        ws.write(row, col, colecttion.garantsum, style1)
        col += 1
        mix = 'да' if colecttion.garantMix > 1 else 'нет'
        ws.write(row, col, mix)
        col += 1
        ws.write(row, col, colecttion.winner['name'], style4)
        col += 1
        if (colecttion.winner['urls'] == 1):
            links = 'один'
        else:
            links = 'поиск'
        urls = colecttion.winner['surls']
        ws.write(row, col,
                 xlwt.Formula(n + '("{0}";"{1}")'.format(urls, links)), style2)
        col += 1
        ws.write(row, col, colecttion.winner['region'])
        col += 1
        ws.write(row, col, colecttion.winner['city'])
        col += 1
        ws.write(row, col, colecttion.winner['phone'])
        col += 1
        ws.write(row, col, colecttion.winner['inn'])
        col += 1
        ws.write(row, col, colecttion.winner['kpp'])
        col += 1
        ws.write(row, col, colecttion.winner['ogrn'])
        row += 1
    wb.save(file_name)
    return 0
from datetime import datetime

import xlwt3 as xlwt

font0 = xlwt.Font()
font0.name = 'Times New Roman'
font0.colour_index = 2
font0.bold = True

style0 = xlwt.XFStyle()
style0.font = font0

style1 = xlwt.XFStyle()
style1.num_format_str = 'D-MMM-YY'

wb = xlwt.Workbook()
ws = wb.add_sheet('A Test Sheet')

ws.write(0, 0, 'Test', style0)
ws.write(1, 0, datetime.now(), style1)
ws.write(2, 0, 1)
ws.write(2, 1, 1)
ws.write(2, 2, xlwt.Formula("A3+B3"))

wb.save('example.xls')