简体   繁体   English

如何使用 python 绘制表格然后另存为图像

[英]How to draw a table using python and then save as a image

Is there a python library that I can use to draw a table and then save it as a image?是否有一个 python 库可以用来绘制表格然后将其保存为图像? The tables are similar to tables the web browsers draw, eg a html table.这些表格类似于 web 浏览器绘制的表格,例如 html 表格。

You can alway draw a table in web page, check the html elements and save the corresponding web content as a html snippet. 您可以始终在网页中绘制表格,检查html元素,并将相应的网页内容另存为html代码段。 So this question can be generalized to: How to convert part of web page(html, css, js) into image ? 因此,这个问题可以概括为:如何将网页的一部分(html,css,js)转换为图像?

Hope this helps solve your problem(a list of library mentioned): Html to image in javascript or python 希望这有助于解决您的问题(提到的库列表): HTML格式的javascript或python图像

pip install pillowdrawtable pip 安装枕头拉出

You can use this python module to draw a table in new_image or draw_object of pillow您可以使用此 python 模块在枕头的 new_image 或 draw_object 中绘制表格

import PIL
from pillowdrawtable.drawtable import Drawtable
text_font =   PIL.ImageFont.truetype("font_path", 100)
header_font =   PIL.ImageFont.truetype("font_path", 90)
table = Drawtable(data=data,
              x=60,
              y=80,
              font=text_font,
              line_spacer=50,
              margin_text=60,
              image_width=5000,
              image_height=1000,
              frame=False,
              grid=False,
              columngrid=True,
              rowgrid=False,
              header=True,
              headerfont=header_font)
table.draw_table()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM