Python实现将Excel转换成为image的方法
作者:杨鑫newlfe 时间:2023-08-10 03:59:55
我的主要思路是:
Excel -> Html -> Image
代码如下:
# -*- coding:utf-8 -*-
__author__ = 'YangXin'
import sys
import pandas as pd
import codecs
import imgkit
reload(sys)
sys.setdefaultencoding('utf-8')
# ReportImage -> report convert include multiple sheets into pictures
class ReportImage:
def __init__(self):
pass
# excel_html -> convert excel include multiple sheets into multiple html file
# excel_file -> file
# html_path -> path
@staticmethod
def excel_html(excel_file, html_path):
html_list = []
excel_obj = pd.ExcelFile(excel_file)
sheet_list = excel_obj.sheet_names
index = 0
for i in sheet_list:
html_file = html_path + i + ".html"
excel_data = excel_obj.parse(excel_obj.sheet_names[index])
with codecs.open(html_file, 'w', 'utf-8') as html:
html.write(excel_data.to_html(header=True, index=True))
html_list.append(html_file)
index += 1
return html_list
# html_image -> convert htmls into pictures file
# html_list -> list
# image_path -> path
@staticmethod
def html_image(html_list, image_path):
index = 0
for i in html_list:
img_obj = image_path + str(index) + ".png"
with open(i, 'r') as html_file:
imgkit.from_file(html_file, img_obj, options={"encoding":"UTF-8"})
index += 1
if __name__ == '__main__':
html_list = ReportImage.excel_html("/xxx.xlsx", "/yyy/")
ReportImage.html_image(html_list, "/zzz/")
来源:https://blog.csdn.net/u012965373/article/details/81273430
标签:Python,Excel,image
0
投稿
猜你喜欢
排序的人文魅力
2008-05-06 12:47:00
mysql中截取字符串的6个函数讲解
2024-01-13 13:54:11
python scrapy爬虫代码及填坑
2022-06-04 01:01:36
详解mysql 获取某个时间段每一天、每一个小时的统计数据
2024-01-17 13:01:47
Python实现合并两个有序链表的方法示例
2023-04-02 22:20:46
laravel清除视图缓存的代码
2023-11-24 14:39:39
Java操作Mysql的方法
2024-01-21 12:28:47
python之tensorflow手把手实例讲解斑马线识别实现
2021-11-11 05:53:19
python增加图像对比度的方法
2022-11-06 09:35:37
javascript实现鼠标点击页面 移动DIV
2024-03-13 07:52:58
Python入门教程(十七)Python的While循环
2022-07-31 13:42:27
Golang接口型函数使用小结
2024-05-08 10:14:53
简单了解为什么python函数后有多个括号
2021-05-11 03:29:35
基于python爬取有道翻译过程图解
2021-11-03 23:57:27
详解MySQL数据库--多表查询--内连接,外连接,子查询,相关子查询
2024-01-24 05:20:34
Firefox下正则诡异问题
2009-08-03 14:03:00
vue文件树组件使用详解
2024-05-09 09:53:52
关于Mysql隔离级别、锁与MVCC介绍
2024-01-16 04:28:26
在python中logger setlevel没有生效的解决
2021-12-13 16:03:01
js中var、let、const之间的区别
2024-04-23 09:11:29