Ejemplo n.º 1
0
def main():
    style0 = xlwt3.easyxf(
        'font: name Times New Roman, color-index red, bold on',
        num_format_str='#,##0.00')
    style1 = xlwt3.easyxf(num_format_str='D-MMM-YY')

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

    ws.write(0, 0, 1234.56, style0)
    ws.write(1, 0, datetime.now(), style1)
    ws.write(2, 0, 1)
    ws.write(2, 1, 1)
    ws.write(2, 2, xlwt3.Formula("A3+B3"))

    wb.save('example.xls')
Ejemplo n.º 2
0
    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')
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
sheet1.write(4, 0, "Stimulus Time")
sheet1.write(4, 1, "Reaction Time")

i=4

for n in list1:
    i = i+1
    sheet1.write(i, 0, n)



book.save("trial.xls")
'''

import xlwt3 as xlwt
from datetime import datetime

style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on',
                     num_format_str='#,##0.00')
style1 = xlwt.easyxf(num_format_str='D-MMM-YY')

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

ws.write(0, 0, 1234.56, 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')
Ejemplo n.º 6
0
    def makeXls(self, tableTitle, outputFilename, tableSubtitle=None):
        nLevels = len(self.levelColLists)
        wb = xlwt.Workbook()
        ws = wb.add_sheet('expenditures')
        styleTableTitle = xlwt.easyxf('font: bold on, height 240')
        styleHeader = xlwt.easyxf('font: bold on; align: wrap on')
        styleThinHeader = xlwt.easyxf(
            'font: bold on, height 180; align: wrap on')
        styleVeryThinHeader = xlwt.easyxf('font: height 140; align: wrap on')
        styleStandard = xlwt.easyxf('')
        styleShallowStandard = xlwt.easyxf('font: bold on')
        styleAmount = xlwt.easyxf(num_format_str='#,##0.0;-#,##0.0;""')
        styleShallowAmount = xlwt.easyxf('font: bold on',
                                         num_format_str='#,##0.0;-#,##0.0;""')
        codeColumnsData = {
            'departmentCode': {
                'text': 'Код ведомства',
                'width': 4,
                'headerStyle': styleVeryThinHeader,
                'cellStyle': styleStandard,
                'shallowCellStyle': styleShallowStandard
            },
            'superSectionCode': {
                'text': 'Код надраздела',
                'width': 5,
                'headerStyle': styleThinHeader,
                'cellStyle': styleStandard,
                'shallowCellStyle': styleShallowStandard
            },
            'sectionCode': {
                'text': 'Код раздела',
                'width': 5,
                'headerStyle': styleThinHeader,
                'cellStyle': styleStandard,
                'shallowCellStyle': styleShallowStandard
            },
            'categoryCode': {
                'text': 'Код целевой статьи',
                'width': 8,
                'headerStyle': styleThinHeader,
                'cellStyle': styleStandard,
                'shallowCellStyle': styleShallowStandard
            },
            'typeCode': {
                'text': 'Код вида расходов',
                'width': 4,
                'headerStyle': styleVeryThinHeader,
                'cellStyle': styleStandard,
                'shallowCellStyle': styleShallowStandard
            },
        }
        columns = [{
            'text': '№ в приложении ' + str(appendix),
            'width': 10,
            'headerStyle': styleThinHeader,
            'cellStyle': styleStandard,
            'shallowCellStyle': styleShallowStandard
        } for appendix in self.yearsInAppendices] + [
            {
                'text': 'Наименование',
                'width': 100,
                'headerStyle': styleHeader,
                'cellStyle': styleStandard,
                'shallowCellStyle': styleShallowStandard
            }
        ] + [
            codeColumnsData[col] for cols in self.levelColLists for col in cols
        ] + [{
            'text': [f(v) for f, v in zip(self.fakeYearNameFns, year)],
            'width': 15,
            'headerStyle': styleHeader,
            'cellStyle': styleAmount,
            'shallowCellStyle': styleShallowAmount
        } for year in self.years]
        ws.set_panes_frozen(True)
        ws.set_horz_split_pos(self.nHeaderRows)
        ws.row(0).height = 400
        ws.merge(0, 0, 0, len(columns) - 1)
        ws.write(0, 0, tableTitle, styleTableTitle)
        if tableSubtitle:
            ws.merge(1, 1, 0, len(columns) - 1)
            ws.write(1, 0, tableSubtitle)
        for i in range(self.nHeaderRows - len(self.fakeYearNameFns),
                       self.nHeaderRows):
            ws.row(i).height = 1200 // len(self.fakeYearNameFns)

        def setCellWidth(nCol, width):
            ws.col(nCol).width = 256 * width

        def writeMergedCellText(nRow1, nCol1, nRow2, nCol2, text, style):
            ws.merge(nRow1, nRow2, nCol1, nCol2)
            ws.write(nRow1, nCol1, text, style)

        self.makeSheetHeader(columns, setCellWidth, ws.write,
                             writeMergedCellText)
        for nRow, row in enumerate(self.outRows):
            for nCol, (cell, col) in enumerate(zip(row, columns)):
                shallow = self.levels[nRow] < nLevels // 2
                style = col['shallowCellStyle' if shallow else 'cellStyle']
                if cell is None:
                    continue
                elif type(cell) is str and cell[0] == '=':
                    ws.write(self.nHeaderRows + nRow, nCol,
                             xlwt.Formula(cell[1:]), style)
                else:
                    ws.write(self.nHeaderRows + nRow, nCol, cell, style)
        wb.save(outputFilename)