Python實(shí)現(xiàn)將Excel轉(zhuǎn)換成為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/")
以上這篇Python實(shí)現(xiàn)將Excel轉(zhuǎn)換成為image的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- python excel轉(zhuǎn)換csv代碼實(shí)例
- python將excel轉(zhuǎn)換為csv的代碼方法總結(jié)
- Python實(shí)現(xiàn)讀取txt文件并轉(zhuǎn)換為excel的方法示例
- Python實(shí)現(xiàn)將Excel轉(zhuǎn)換為json的方法示例
- 利用python將圖片轉(zhuǎn)換成excel文檔格式
- python利用pandas將excel文件轉(zhuǎn)換為txt文件的方法
- Python實(shí)現(xiàn)將Excel轉(zhuǎn)換成xml的方法示例
- python實(shí)現(xiàn)Excel文件轉(zhuǎn)換為TXT文件
- python使用xlsxwriter實(shí)現(xiàn)有向無(wú)環(huán)圖到Excel的轉(zhuǎn)換
- Python編程快速上手——Excel到CSV的轉(zhuǎn)換程序案例分析
相關(guān)文章
Python3中函數(shù)參數(shù)傳遞方式實(shí)例詳解
這篇文章主要介紹了Python3中函數(shù)參數(shù)傳遞方式,結(jié)合實(shí)例形式較為詳細(xì)的分析了Python3中函數(shù)參數(shù)傳遞的常見(jiàn)操作技巧,需要的朋友可以參考下2019-05-05python實(shí)現(xiàn)簡(jiǎn)單登陸流程的方法
下面小編就為大家分享一篇python實(shí)現(xiàn)簡(jiǎn)單登陸流程的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-04-04python中數(shù)組和矩陣乘法及使用總結(jié)(推薦)
這篇文章主要介紹了python中數(shù)組和矩陣乘法及使用總結(jié),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05詳解Python 2.6 升級(jí)至 Python 2.7 的實(shí)踐心得
本篇文章主要介紹了詳解Python 2.6 升級(jí)至 Python 2.7 的實(shí)踐心得,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04DjangoWeb使用Datatable進(jìn)行后端分頁(yè)的實(shí)現(xiàn)
這篇文章主要介紹了DjangoWeb使用Datatable進(jìn)行后端分頁(yè)的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-05-05python學(xué)習(xí)之whl文件解釋與安裝詳解
whl格式本質(zhì)上是一個(gè)壓縮包,里面包含了py文件,以及經(jīng)過(guò)編譯的pyd文件,下面這篇文章主要給大家介紹了關(guān)于python學(xué)習(xí)之whl文件解釋與安裝的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09Python利用Pytorch實(shí)現(xiàn)繪制ROC與PR曲線圖
這篇文章主要和大家分享一下Python利用Pytorch實(shí)現(xiàn)繪制ROC與PR曲線圖的相關(guān)代碼,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的可以參考一下2022-12-12