国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實現(xiàn)將Excel轉(zhuǎn)換成為image的方法

2020-02-15 23:22:05
字體:
供稿:網(wǎng)友

我的主要思路是:

Excel -> Html -> Image

代碼如下:

# -*- coding:utf-8 -*-__author__ = 'YangXin'import sysimport pandas as pdimport codecsimport imgkitreload(sys)sys.setdefaultencoding('utf-8')  # ReportImage -> report convert include multiple sheets into picturesclass 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實現(xiàn)將Excel轉(zhuǎn)換成為image的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 铁力市| 赞皇县| 青岛市| 德钦县| 彩票| 乌苏市| 香格里拉县| 南京市| 酒泉市| 康保县| 鄂托克旗| 延津县| 康乐县| 龙陵县| 广南县| 玉屏| 长子县| 泗水县| 荥经县| 金山区| 宝丰县| 永清县| 建始县| 图片| 长沙县| 溆浦县| 阿勒泰市| 乐安县| 安顺市| 邯郸县| 凌海市| 阿克苏市| 林周县| 监利县| 察雅县| 鄱阳县| 永州市| 德令哈市| 安远县| 绥阳县| 普洱|