在python中创建发布质量表

2024-03-29 13:20:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我想创建发布质量表,以便使用python将其输出为svg、jpg或png图像。

我熟悉texttable模块,它可以生成漂亮的文本表,但是如果我有

data = [['Head 1','Head 2','Head 3'],['Sample Set Type 1',12.8,True],['Sample Set Type 2',15.7,False]]

我想做一些看起来像

table image

有没有一个模块我可以转向,或者你能给我指一个过程来进行吗?


Tags: 模块samplesvg图像文本falsetruedata
1条回答
网友
1楼 · 发布于 2024-03-29 13:20:50

感觉像是http://matplotlib.org/的工作,就像https://stackoverflow.com/a/8976359/447599

也可以是ReportLab的工作,如Python reportlab inserting image into table

另一个选项是根据http://en.wikibooks.org/wiki/LaTeX/Tables以表格形式输出乳胶源

如果这不适合您,只需编写.csv文件并在excel中格式化表格,然后在那里导出图像表单,代码如下

with open("example.csv") as of:
    for row in data:
        for cell in row:
             of.write(cell + ";")
        of.write("\n")

我想你也可以写一个html表格文件,然后用css来设置它的样式。

with open("example.html") as of:
    of.write("<html><table>")
    for index, row in enumerate(data):
        if index == 0:
             of.write("<th>")
        else:
             of.write("<tr>")
        for cell in row:
             of.write("<td>" + cell + "</td>")
        if index == 0:
             of.write("</th>")
        else:
             of.write("</tr>")
    of.write("</table></html>")

相关问题 更多 >