python将excel转换成图片_Python实现将Excel转换成为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/")

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值