首页 > 解决方案 > 在python中格式化HTML字体和颜色

问题描述

我编写了一个函数,它在 Confluence 中创建一个网页,列出我们账户中的所有 AWS Ec2 实例。这看起来不错的样子。

除了背景全是灰色的,字体到处都是粗体。

这是我的功能:

def convert_csv_to_html_table(output_file, today):
    output_dir = "../output_files/aws_instance_list/html/"
    htmlfile = output_dir + 'aws-master-list-' + today +'.html'
    count = 0
    html = ''
    with open(output_file,'r') as CSVFILE:
        reader = csv.reader(CSVFILE)
        html += "<table><tbody>"
        for row in reader:
            html += "<tr>"
            # Process the headers
            if count == 0:
                for column in row:
                    html += "<th>%s</th>" % column
                html += "</tr>"
            else:
                # Process the data
                for column in row:
                    html += "<td>%s</td>" % column
                html += "</tr>"
                count += 1
        html += "</tbody></table>"
    with open(htmlfile,'w+') as HTMLFILE:
        HTMLFILE.write(html)
    return htmlfile

我怎样才能得到只有标题有灰色背景的结果?页面的其余部分有白色背景?另外如何在上面的代码中指定字体和字体大小?

标签: python

解决方案


推荐阅读