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 相关文章推荐
Python中条件选择和循环语句使用方法介绍
Mar 13 Python
python的re模块应用实例
Sep 26 Python
使用Python写个小监控
Jan 27 Python
Python中shutil模块的常用文件操作函数用法示例
Jul 05 Python
python 字符串转列表 list 出现\ufeff的解决方法
Jun 22 Python
Python元组操作实例分析【创建、赋值、更新、删除等】
Jul 24 Python
python操作excel的方法(xlsxwriter包的使用)
Jun 11 Python
python退出命令是什么?详解python退出方法
Dec 10 Python
python实现给scatter设置颜色渐变条colorbar的方法
Dec 13 Python
Django unittest 设置跳过某些case的方法
Dec 26 Python
深入了解和应用Python 装饰器 @decorator
Apr 02 Python
Python 字节流,字符串,十六进制相互转换实例(binascii,bytes)
May 11 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 常用字符串函数总结
2008/03/15 PHP
PHP中$_SERVER的详细参数与说明
2008/07/29 PHP
PHP 创建文件(文件夹)以及目录操作代码
2010/03/04 PHP
PHP中捕获超时事件的方法实例
2015/02/12 PHP
php猴子选大王问题解决方法
2015/05/12 PHP
PHP使用http_build_query()构造URL字符串的方法
2016/04/02 PHP
浅析PHP中的闭包和匿名函数
2017/12/25 PHP
Yii 框架控制器创建使用及控制器响应操作示例
2019/10/14 PHP
在JavaScript中遭遇级联表达式陷阱
2007/03/08 Javascript
jQuery库与其他JS库冲突的解决办法
2010/02/07 Javascript
Jquery多选框互相内容交换的实例代码
2013/07/04 Javascript
JS文本框默认值处理详解
2013/07/10 Javascript
js中parseInt函数浅谈
2013/07/31 Javascript
JSP跨iframe如何传递参数实现代码
2013/09/21 Javascript
AngularJS控制器controller正确的通信的方法
2016/01/25 Javascript
PHP实现本地图片上传和验证功能
2017/02/27 Javascript
Bootstrap.css与layDate日期选择样式起冲突的解决办法
2017/04/07 Javascript
Vue2路由动画效果的实现代码
2017/07/10 Javascript
JS中appendChild追加子节点无效的解决方法
2018/10/14 Javascript
vue-cli3配置favicon.ico和title的流程
2020/10/27 Javascript
ant design中upload组件上传大文件,显示进度条进度的实例
2020/10/29 Javascript
[48:45]Ti4 循环赛第二日 NEWBEE vs EG
2014/07/11 DOTA
Python基于hashlib模块的文件MD5一致性加密验证示例
2018/02/10 Python
python2与python3爬虫中get与post对比解析
2019/09/18 Python
Python实现实时数据采集新型冠状病毒数据实例
2020/02/04 Python
pyecharts调整图例与各板块的位置间距实例
2020/05/16 Python
基于keras中的回调函数用法说明
2020/06/17 Python
浅谈keras通过model.fit_generator训练模型(节省内存)
2020/06/17 Python
python 生成器需注意的小问题
2020/09/29 Python
CSS图片翻转动画技术详解(IE也实现了)
2014/04/03 HTML / CSS
绩效工资分配方案
2014/01/18 职场文书
动物科学专业求职信
2014/07/27 职场文书
出国签证在职证明
2014/09/20 职场文书
餐厅服务员岗位职责
2015/02/09 职场文书
决心书格式及范文
2019/06/24 职场文书
centos8安装nginx1.9.1的详细过程
2021/08/02 Servers