Ejemplo n.º 1
0
def output_html(rowData):
    """
    :param rowData: 行数据, 元祖数据,逗号分隔,格式为(
        ('2020/10/18', 'HO1234', '上海', '上海', '10:00~12:00', '可兑换'),
        ('2020/10/18', 'HO1234', '上海', '上海', '10:00~12:00', '可兑换'),)
    :return: html 内容
    """
    nowTime = time.strftime('%Y-%m-%d %H:%M:%S')
    # 标题
    table = HTMLTable(caption='吉祥航空畅心飞余票概览(%s更新)' % nowTime)
    table.append_header_rows(
        (('日期', '始发城市', '目的城市', '航班', '航线', '时间', '耗时', '畅飞卡座位'), ))

    # 表格内容
    table.append_data_rows(rowData)

    # 表格样式,即<table>标签样式
    table.set_style({
        'border-collapse': 'collapse',
        'word-break': 'keep-all',
        'white-space': 'nowrap',
        'font-size': '14px',
    })

    # 统一设置所有单元格样式,<td>或<th>
    table.set_cell_style({
        'border-color': '#000',
        'border-width': '1px',
        'border-style': 'solid',
        'padding': '5px',
    })

    # 表头样式
    table.set_header_row_style({
        'color': '#fff',
        'background-color': '#48a6fb',
        'font-size': '18px',
    })

    # 覆盖表头单元格字体样式
    table.set_header_cell_style({
        'padding': '15px',
    })
    html = table.to_html()
    return html
Ejemplo n.º 2
0
def list_to_html_table(in_list):
    table = HTMLTable(caption="表格的标题")
    title = in_list[0]
    # print(temp)
    table.append_header_rows((title, ()))
    content = in_list[1:]
    table.append_data_rows(content)
    # 表格样式,即<table>标签样式
    table.set_style({
        'border-collapse': 'collapse',
        'word-break': 'keep-all',
        'white-space': 'nowrap',
        'font-size': '13px',
        'font-family': 'Microsoft Yahei UI',
    })
    # 表头样式
    table.set_header_row_style({
        'font-size': '13px',
    })
    # 统一设置所有单元格样式,<td>或<th>
    table.set_cell_style({
        'border-color': '#000',
        'border-width': '1px',
        'border-style': 'solid',
        'padding': '3px',
    })
    # 覆盖表头单元格字体样式
    table.set_header_cell_style({
        'padding': '5px',
    })
    # 遍历数据行,满足特定条件,行标记特殊颜色
    for row in table.iter_data_rows():
        if str(row[4].value) != "" and str(row[4].value).find("预计") == -1:
            row.set_style({
                'background-color': '#ccffcc',
            })
    html = table.to_html()
    html = html.replace('\"', '\'')
    # print(html)
    return html
Ejemplo n.º 3
0
table.set_cell_style({
    'border-color': '#000',
    'border-width': '1px',
    'border-style': 'solid',
    'padding': '5px',
})

# 表头样式
table.set_header_row_style({
    'color': '#fff',
    'background-color': '#48a6fb',
    'font-size': '18px',
})
# 覆盖表头单元格字体样式
table.set_header_cell_style({
    'padding': '15px',
})

# 调小次表头字体大小
table[1].set_cell_style({
    'padding': '8px',
    'font-size': '15px',
})

# 遍历数据行,如果增长量为负,标红背景颜色
for row in table.iter_data_rows():
    if row[2].value < 0:
        row.set_style({
            'background-color': '#ffdddd',
        })
Ejemplo n.º 4
0
def create_HTML():
    # 标题
    table = HTMLTable(caption='测试报告')
    # 表头行
    table.append_header_rows((
        ('名称', '产量 (吨)', '环比', ''),
        ('', '', '增长量 (吨)', '增长率 (%)'),
    ))

    # 合并单元格
    table[0][0].attr.rowspan = 2
    table[0][1].attr.rowspan = 2
    table[0][2].attr.colspan = 2

    # 数据行
    table.append_data_rows((
        ('荔枝', 11, 1, 10),
        ('芒果', 9, -1, -10),
        ('香蕉', 6, 1, 20),
    ))

    # 标题样式
    table.caption.set_style({
        'font-size': '15px',
    })

    # 表格样式,即<table>标签样式
    table.set_style({
        'border-collapse': 'collapse',
        'word-break': 'keep-all',
        'white-space': 'nowrap',
        'font-size': '14px',
    })

    # 统一设置所有单元格样式,<td>或<th>
    table.set_cell_style({
        'border-color': '#000',
        'border-width': '1px',
        'border-style': 'solid',
        'padding': '5px',
    })

    # 表头样式
    table.set_header_row_style({
        'color': '#fff',
        'background-color': '#48a6fb',
        'font-size': '18px',
    })

    table.set_header_cell_style({
        'padding': '15px',
    })

    # 调小次表头字体大小
    table[1].set_cell_style({
        'padding': '8px',
        'font-size': '15px',
    })

    # 遍历数据行,如果增长量为负,标红背景颜色
    for row in table.iter_data_rows():
        if row[2].value < 0:
            row.set_style({
                'background-color': '#ffdddd',
            })

    html = table.to_html()
    with open("test.html", "w+") as f:
        f.write(html)
Ejemplo n.º 5
0
def build_excel_html():
    from HTMLTable import HTMLTable
    # 生成表名
    table = HTMLTable(caption='运维巡检系统本周报表\n')
    # 生成首行
    table.append_header_rows((('事件', '对象', '触发条件', '当前值'), ))
    # 获取规则id对应异常数量的dict
    all_count_dict = get_method_count()
    # 将方法列为列表
    column0 = list(all_count_dict)
    for j in column0:
        sql = "select id, method_name, reference_value, compare from %s where expression_name = '%s'" % (
            rules_table, j)
        expression_id = mysql_conn.select(sql)[0][0]
        method_name = mysql_conn.select(sql)[0][1]
        reference_value = mysql_conn.select(sql)[0][2]
        compare = mysql_conn.select(sql)[0][3]
        sql = "select comments from %s where name = '%s'" % (methods_table,
                                                             method_name)
        comments = mysql_conn.select(sql)[0][0]
        sql = "select gps_object, value from %s where expression_id = '%s' and status = 1" % (
            problem_table, expression_id)
        result = mysql_conn.select(sql)
        for bb in range(0, all_count_dict[j]):
            gps_object = result[bb][0]
            value = result[bb][1]
            table.append_data_rows(
                ((comments, gps_object, str(compare) + str(reference_value),
                  value), ))
    # 标题样式
    table.caption.set_style({
        'font-size': '20px',
    })
    # 表格样式,即<table>标签样式
    table.set_style({
        'border-collapse': 'collapse',
        'word-break': 'keep-all',
        'white-space': 'nowrap',
        'font-size': '14px',
    })
    # 统一设置所有单元格样式,<td>或<th>
    table.set_cell_style({
        'border-color': '#000',
        'border-width': '1px',
        'border-style': 'solid',
        'padding': '5px',
        'text-align': 'center',  # 单元格居中
    })
    # 表头样式
    table.set_header_row_style({
        'color': '#fff',
        'background-color': '#48a6fb',
        'font-size': '18px',
    })

    # 覆盖表头单元格字体样式
    table.set_header_cell_style({
        'padding': '15px',
    })
    html = table.to_html()
    return html
Ejemplo n.º 6
0
def gen_html():
    # 标题
    table = HTMLTable(caption='商品销量表')

    # 表头行
    table.append_header_rows((
        ('名称', '销量(件)', '环比', ''),
        ('', '', '增长量 (件)', '增长率 (%)'),
    ))

    # 合并单元格
    table[0][0].attr.rowspan = 2
    table[0][1].attr.rowspan = 2
    table[0][2].attr.colspan = 2

    # 数据行
    table.append_data_rows((
        ('牛仔裤', 110, 10, 20),
        ('T恤', 20, 20, -9),
        ('Nike鞋', 50, 22, 10),
    ))

    # 标题样式
    table.caption.set_style({
        'font-size': '15px',
    })

    # 表格样式,即<table>标签样式
    table.set_style({
        'border-collapse': 'collapse',
        'word-break': 'keep-all',
        'white-space': 'nowrap',
        'font-size': '14px',
    })

    # 统一设置所有单元格样式,<td>或<th>
    table.set_cell_style({
        'border-color': '#000',
        'border-width': '1px',
        'border-style': 'solid',
        'padding': '5px',
    })

    # 表头样式
    table.set_header_row_style({
        'color': '#fff',
        'background-color': '#48a6fb',
        'font-size': '18px',
    })

    # 覆盖表头单元格字体样式
    table.set_header_cell_style({
        'padding': '15px',
    })

    # 调小次表头字体大小
    table[1].set_cell_style({
        'padding': '8px',
        'font-size': '15px',
    })

    # 遍历数据行,如果增长量为负,标红背景颜色
    for row in table.iter_data_rows():
        if row[2].value < 0:
            row.set_style({
                'background-color': '#ffdddd',
            })

    html = table.to_html()
    print(html)