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 机器学习库 NumPy入门教程
Apr 19 Python
python同时遍历数组的索引和值的实例
Nov 15 Python
python如何读取bin文件并下发串口
Jul 05 Python
python3.6 tkinter实现屏保小程序
Jul 30 Python
python paramiko远程服务器终端操作过程解析
Dec 14 Python
python pprint模块中print()和pprint()两者的区别
Feb 10 Python
详解python环境安装selenium和手动下载安装selenium的方法
Mar 17 Python
Python函数基本使用原理详解
Mar 19 Python
Django中F函数的使用示例代码详解
Jul 06 Python
解决python便携版无法直接运行py文件的问题
Sep 01 Python
详解BeautifulSoup获取特定标签下内容的方法
Dec 07 Python
python turtle绘制多边形和跳跃和改变速度特效
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编实现程动态图像的创建代码
2008/09/28 PHP
php中使用explode查找某个字符是否存在的方法
2011/07/12 PHP
php将日期格式转换成xx天前的格式
2015/04/16 PHP
php中通用的excel导出方法实例
2017/12/30 PHP
php-fpm服务启动脚本的方法
2018/04/27 PHP
PHP实现的多维数组去重操作示例
2018/07/21 PHP
PHP常用工具函数小结【移除XSS攻击、UTF8与GBK编码转换等】
2019/04/27 PHP
使用javascript访问XML数据的实例
2006/12/27 Javascript
jquery select(列表)的操作(取值/赋值)
2009/08/06 Javascript
jquery miniui 教程 表格控件 合并单元格应用
2012/11/25 Javascript
JS中引用百度地图并将百度地图的logo和信息去掉
2013/09/29 Javascript
express的中间件cookieParser详解
2014/12/04 Javascript
JavaScript实现模仿桌面窗口的方法
2015/07/18 Javascript
使用jQuery判断Div是否在可视区域的方法 判断div是否可见
2016/02/17 Javascript
js判断图片加载完成后获取图片实际宽高的方法
2016/02/25 Javascript
JavaScript驾驭网页-DOM
2016/03/24 Javascript
JS获取当前使用的浏览器名字以及版本号实现方法
2016/08/19 Javascript
vue2.0开发实践总结之疑难篇
2016/12/07 Javascript
bootstrap配合Masonry插件实现瀑布式布局
2017/01/18 Javascript
xmlplus组件设计系列之按钮(2)
2017/04/26 Javascript
详解微信小程序胶囊按钮返回|首页自定义导航栏功能
2019/06/14 Javascript
微信小程序自定义组件components(代码详解)
2019/10/21 Javascript
微信小程序淘宝首页双排图片布局排版代码(推荐)
2020/10/29 Javascript
Python查找函数f(x)=0根的解决方法
2015/05/07 Python
scrapy爬虫完整实例
2018/01/25 Python
解决python写入mysql中datetime类型遇到的问题
2018/06/21 Python
Python生成pdf目录书签的实例方法
2020/10/29 Python
XD健身器材:Kevlar球、Crossfit健身球
2019/03/26 全球购物
资产评估专业大学生求职信
2013/09/29 职场文书
个人简历自我评价
2014/02/02 职场文书
2014年妇女工作总结
2014/12/06 职场文书
初中重阳节活动总结
2015/05/05 职场文书
单位车辆管理制度
2015/08/05 职场文书
浅谈:电影《孔子》观后感(范文)
2019/10/14 职场文书
基于python定位棋子位置及识别棋子颜色
2021/07/26 Python
Win10/Win11 任务栏替换成经典样式
2022/04/19 数码科技