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 相关文章推荐
详解Python2.x中对Unicode编码的使用
Apr 03 Python
Python下的subprocess模块的入门指引
Apr 16 Python
Python使用QRCode模块生成二维码实例详解
Jun 14 Python
python操作excel的方法(xlsxwriter包的使用)
Jun 11 Python
python3使用pandas获取股票数据的方法
Dec 22 Python
Python高级property属性用法实例分析
Nov 19 Python
pytorch实现onehot编码转为普通label标签
Jan 02 Python
Python 在函数上添加包装器
Jul 28 Python
如何将json数据转换为python数据
Sep 04 Python
Python判断变量是否是None写法代码实例
Oct 09 Python
如何用python实现一个HTTP连接池
Jan 14 Python
Python3的进程和线程你了解吗
Mar 16 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入门教程之字符串处理技巧总结(转换,过滤,解析,查找,截取,替换等)
2016/09/11 PHP
PHP实现加密文本文件并限制特定页面的存取的效果
2016/10/21 PHP
javascript 操作select下拉列表框的一点小经验
2010/03/20 Javascript
基于jQuery的弹出消息插件 DivAlert之旅(一)
2010/04/01 Javascript
基于jQuery实现下拉收缩(展开与折叠)特效
2012/12/25 Javascript
jQuery 1.9使用$.support替代$.browser的使用方法
2014/05/27 Javascript
js动态往表格的td中添加图片并注册事件
2014/06/12 Javascript
基于 Docker 开发 NodeJS 应用
2014/07/30 NodeJs
基于javascript实现单选及多选的向右和向左移动实例
2015/07/25 Javascript
javascript伸缩菜单栏实现代码分享
2015/11/12 Javascript
使用vue.js制作分页组件
2016/06/27 Javascript
jquery-mobile基础属性与用法详解
2016/11/23 Javascript
基于Particles.js制作超炫粒子动态背景效果(仿知乎)
2017/09/13 Javascript
javaScript canvas实现(画笔大小 颜色 橡皮的实例)
2017/11/28 Javascript
Angular4的输入属性与输出属性实例详解
2017/11/29 Javascript
AngularJS实现的生成随机数与猜数字大小功能示例
2017/12/25 Javascript
vue实现可视化可拖放的自定义表单的示例代码
2019/03/20 Javascript
Python中装饰器高级用法详解
2017/12/25 Python
Django中create和save方法的不同
2019/08/13 Python
Python 实现文件读写、坐标寻址、查找替换功能
2019/09/11 Python
python实现获取单向链表倒数第k个结点的值示例
2019/10/24 Python
Django中modelform组件实例用法总结
2020/02/10 Python
基于python爬取链家二手房信息代码示例
2020/10/21 Python
python绕过图片滑动验证码实现爬取PTA所有题目功能 附源码
2021/01/06 Python
使用 css3 transform 属性来变换背景图的方法
2019/05/07 HTML / CSS
欧迪办公美国官网:Office Depot
2016/08/22 全球购物
学术会议邀请函范文
2014/01/22 职场文书
运动会解说词100字
2014/01/31 职场文书
2015年酒店服务员工作总结
2015/05/18 职场文书
劳动仲裁代理词范文
2015/05/25 职场文书
高中诗歌鉴赏教学反思
2016/02/16 职场文书
《夸父追日》教学反思
2016/02/20 职场文书
2016年基层党支部书记公开承诺书
2016/03/25 职场文书
Redis如何一键部署脚本
2021/04/12 Redis
golang http使用踩过的坑与填坑指南
2021/04/27 Golang
如何判断pytorch是否支持GPU加速
2021/06/01 Python