国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 独山县| 新竹市| 马山县| 嵊州市| 鞍山市| 长武县| 肃北| 绥宁县| 同心县| 林甸县| 诸暨市| 赤城县| 南宫市| 本溪| 延边| 将乐县| 大荔县| 邮箱| 偃师市| 峨山| 海阳市| 陵水| 二连浩特市| 交口县| 德保县| 巩留县| 牙克石市| 观塘区| 友谊县| 儋州市| 西盟| 南漳县| 陈巴尔虎旗| 雷州市| 香格里拉县| 万年县| 洛浦县| 涞源县| 桐乡市| 彰武县| 岐山县|