本文章向大家介绍使用Python怎么将Excel转换成image,主要包括使用Python怎么将Excel转换成image的使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
Python是一种跨平台的、具有解释性、编译性、互动性和面向对象的脚本语言,其最初的设计是用于编写自动化脚本,随着版本的不断更新和新功能的添加,常用于用于开发独立的项目和大型项目。
我的主要思路是:
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/")
到此这篇关于使用Python怎么将Excel转换成image的文章就介绍到这了,更多相关的内容请搜索亿速云以前的文章或继续浏览下面的相关文章希望大家以后多多支持亿速云!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。