Python实现将Excel转换成为image的方法


Posted in Python onOctober 23, 2018

我的主要思路是:

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的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
rhythmbox中文名乱码问题解决方法
Sep 06 Python
python BeautifulSoup设置页面编码的方法
Apr 03 Python
Python+MongoDB自增键值的简单实现
Nov 04 Python
python 类详解及简单实例
Mar 24 Python
Python实现PS图像调整之对比度调整功能示例
Jan 26 Python
pycharm使用matplotlib.pyplot不显示图形的解决方法
Oct 28 Python
python利用requests库模拟post请求时json的使用教程
Dec 07 Python
基于Python实现用户管理系统
Feb 26 Python
安装2019Pycharm最新版本的教程详解
Oct 22 Python
python 消除 futureWarning问题的解决
Dec 25 Python
为什么说python适合写爬虫
Jun 11 Python
Python绘制分类图的方法
Apr 20 Python
python pandas实现excel转为html格式的方法
Oct 23 #Python
使用11行Python代码盗取了室友的U盘内容
Oct 23 #Python
python利用pandas将excel文件转换为txt文件的方法
Oct 23 #Python
python实现根据指定字符截取对应的行的内容方法
Oct 23 #Python
python中正则表达式 re.findall 用法
Oct 23 #Python
python 实现批量xls文件转csv文件的方法
Oct 23 #Python
python 把列表转化为字符串的方法
Oct 23 #Python
You might like
php 按指定元素值去除数组元素的实现方法
2011/11/04 PHP
关于IIS php调用com组件的权限问题
2012/01/11 PHP
利用PHP+JS实现搜索自动提示(实例)
2013/06/09 PHP
兼容IE、FireFox、Chrome等浏览器的xml处理函数js代码
2011/11/30 Javascript
『jQuery』取指定url格式及分割函数应用
2013/04/22 Javascript
jquery中交替点击事件toggle方法的使用示例
2013/12/08 Javascript
一个css与js结合的下拉菜单支持主流浏览器
2014/10/08 Javascript
FF(火狐)浏览器无法执行window.close()解决方案
2014/11/13 Javascript
js实现不提交表单获取单选按钮值的方法
2015/08/21 Javascript
jquery实现简易的移动端验证表单
2015/11/08 Javascript
基于javascript实现动态显示当前系统时间
2016/01/28 Javascript
JS实现根据文件字节数返回文件大小的方法
2016/08/02 Javascript
Javascript发送AJAX请求实例代码
2016/08/21 Javascript
React中ES5与ES6写法的区别总结
2017/04/21 Javascript
详解AngularJS 过滤器的使用
2018/06/02 Javascript
layui清空,重置表单数据的实例
2019/09/12 Javascript
解决LayUI加上form.render()下拉框和单选以及复选框不出来的问题
2019/09/27 Javascript
JavaScript队列结构Queue实现过程解析
2020/03/07 Javascript
javascrpt密码强度校验函数详解
2020/03/18 Javascript
webpack 动态批量加载文件的实现方法
2020/03/19 Javascript
[33:33]完美世界DOTA2联赛PWL S2 FTD.C vs SZ 第二场 11.27
2020/11/30 DOTA
Python 匹配任意字符(包括换行符)的正则表达式写法
2009/10/29 Python
Python网页正文转换语音文件的操作方法
2018/12/09 Python
用python实现刷点击率的示例代码
2019/02/21 Python
Pyqt5 基本界面组件之inputDialog的使用
2019/06/25 Python
Python绘制频率分布直方图的示例
2019/07/08 Python
Python的bit_length函数来二进制的位数方法
2019/08/27 Python
python中列表的含义及用法
2020/05/26 Python
查找适用于matplotlib的中文字体名称与实际文件名对应关系的方法
2021/01/05 Python
canvas如何实现多张图片编辑的图片编辑器
2020/03/10 HTML / CSS
瑞典网上购买现代和复古家具:Reforma
2019/10/21 全球购物
服装公司总经理岗位职责
2013/11/30 职场文书
公司会计岗位职责
2014/02/13 职场文书
六年级情感作文之500字
2019/10/23 职场文书
pandas 操作 Excel操作总结
2021/03/31 Python
PyTorch 如何自动计算梯度
2021/05/23 Python