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
0
投稿
猜你喜欢
- 我就废话不多说了,大家还是直接看代码吧!绘制曲线:import timeimport numpy as npimport matplotli
- 打开php.ini,首先找到;;;;;;;;;;;;;;;;; file uploads ;;;;;;;;;;;;;;;;;区域,有影响文件
- 记录了Windows安装python3.7的详细过程,供大家参考,具体内容如下1. 在python的官网下载python对应版本:官网地址6
- go-ini的分区go-ini的多个配置项通过分区(section)来划分。有默认(空)分区和命名的分区,没有给分区命名就是默认分区,默认分
- 在java的应用中,我们经常会对数据库进行必要的操作,下来我们就了解一下如何用java连接mysql数据库 以及java连接sql serv
- 叨叨几句哈喽兄弟们,今天实现一下人脸识别。先问大家一个问题什么是百度Aip模块?百度AI平台提供了很多的API接口供开发者快速的调用运用在项
- 在 CodeBit.cn 的论坛中,有人问 Javascript 中如何截取小数位并实现四舍五入,这是一个很常用的 js 技术,帖子中也有网
- 最近给卫生局做一个表格上传/可视化系统,算是小有成果。今天把项目中的文件拖拽上传模块分离出来,做了一个独立的小demo,并把相关代码打包上传
- on里面的xlrd模块详解(一) - 疯了的小蜗 - 博客园【内容】:>那我就一下面积个问题对xlrd模块进行学习一下:什么是xlrd
- 代码如下:<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001&quo
- 本文实例讲述了python通过定义一个类实例作为ftp回调方法。分享给大家供大家参考。具体实现方法如下:class Writer: &nbs
- 在默认情况下,Access 2000/2002数据库是以“共享”的方式打开的,这样可以保证多人能够同时使用同一个数据库。不过,在共享方式打开
- 1. 新建项目在命令行窗口下输入scrapy startproject scrapytest, 如下然后就自动创建了相应的文件,如下2. 修
- 使用一阶线性方程预测波士顿房价载入的数据是随sklearn一起发布的,来自boston 1993年之前收集的506个房屋的数据和价格。loa
- 来与大家分享。稍加改造就可以实现更强大的功能了。用下面的代码就可以简单的批量导出picasa相册的外链了。代码如下:<%@LANGUA
- 在使用tensorflow时常常会使用到tf.reduce_*这类的函数,在此对一些常见的函数进行汇总1.tf.reduce_sumtf.r
- #pd.to_datetime函数#读取数据import pandas as pddata = pd.read_csv('polic
- 简单介绍下功能吧:使用了ASP的一个对象ServerVariables(服务器环境变量),通过这个环境变量可以获取到真正的下载地址再通过一些
- Python文件遍历os.walk()与os.listdir()在图片处理过程中,样本数据的组织是个常见的问题,样本组织好了,后面数据转换、
- 前言内存映射通常可以提高I/O的性能,因为使用内存映射时,不需要对每个访问都建立一个单独的系统调用,也不需要在缓冲区之间复制数据,内核和用户