Python实现将Excel转换成为image的方法
作者:杨鑫newlfe 发布时间:2023-08-10 03:59:55
标签:Python,Excel,image
我的主要思路是:
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/")
来源:https://blog.csdn.net/u012965373/article/details/81273430


猜你喜欢
- 今天小编利用美丽的汤来为大家演示一下如何实现京东商品信息的精准匹配~~HTML文件其实就是由一组尖括号构成的标签组织起来的,每一对尖括号形式
- 说明1、字典运算中的键必须是不可变类型,如整数(int)、浮点数(float)、字符串(str)、元组(tuple)等。2、列表(list)
- 本文介绍Python3使用PyMySQL连接数据库,并实现简单的增删改查。什么是PyMySQL?PyMySQL是Python3.x版本中用于
- 本文实例讲述了Python Datetime模块和Calendar模块用法。分享给大家供大家参考,具体如下:datetime模块1.1 概述
- 因为有把python程序打包成exe的需求,所以,有了如下的代码import timeclass LoopOver(Exception):
- 为什么要 mock?后台接口还没完成,但前端要用到接口我想篡改后台接口的结果,测试一些分支逻辑起步本篇文章会使用到 swr、axios、vi
- 今天来聊一下 Go 如何使用 set,本文将会涉及 set 和 bitset 两种数据结构。Go 的数据结构Go 内置的数据结构并不多。工作
- 每一字符串字符文字有一个字符集和一个校对规则,它不能为空。一个字符串文字可能有一个可选的字符集引介词和COLLATE子句:[_charset
- 今天使用pip安装第三库时,有时会报错:pip._vendor.urllib3.exceptions.ReadTimeoutError: H
- 一、卷积神经网络Yann LeCun 和Yoshua Bengio在1995年引入了卷积神经网络,也称为卷积网络或CNN。CNN是一种特殊的
- 网上看到一个python写的数独,很好玩,分享给大家。import randomimport itertoolsfrom copy impo
- 在SQL Server数据库中,有min server memory与max server memory两个内存选项。数据库管理员合理设置这
- 之前用Python 2.7版本的httplib做接口测试时,运行代码都是正常的,最近开始用Python 3.3之后,再去看以前的代码,发现i
- 在SQL Server中,为了查询性能的优化,有时我们就需要对数据表通过建立索引的方式,目的主要是根据查询要求,迅速缩小查询范围,避免全表扫
- 在网页局部的布局上,需要采用大量的自适应,来满足不同长度数据、内容的合理呈现。以此保证页面不至于因为内容过多等原因,导致重叠、溢出、撑开等破
- 如何在PYTHON里运用私有属性和方法class File:def __init__(self, name):self.name = nam
- 前言最近公司项目从vue2迁移到vue3,感觉自己对Object.defineProperty和Proxy的了解还是在浅尝辄止的地步,所以今
- 如今,体育运动的热潮日益流行。同样,以不正确的方式进行运动的风险也在增加。有时可能会导致严重的伤害。考虑到这些原因,提出一种以分析运动员的关
- AIML全名为Artificial Intelligence Markup Language(人工智能标记语言),是一种创建自然语言软件代理
- 一、动机(Motivate)“观察者模式”在现实生活中,实例其实是很多的,比如:八九十年代我们订阅的