Python将Excel工作表范围导出为图像 [英] Python Export Excel Sheet Range as Image

查看:158
本文介绍了Python将Excel工作表范围导出为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以看来PIL ImageGrab.grabclipboard()发生了一些奇怪的事情

So it seems there's something weird going on with PIL ImageGrab.grabclipboard()

import win32com.client
from PIL import ImageGrab

o = win32com.client.Dispatch('Excel.Application')
o.visible = False

wb = o.Workbooks.Open(path)
ws = wb.Worksheets['Global Dash']

ws.Range(ws.Cells(1,1),ws.Cells(66,16)).CopyPicture()  
img = ImageGrab.grabclipboard()
imgFile = os.path.join(path_to_img,'test.jpg')
img.save(imgFile)

运行此命令时,我注意到如果我ctrl-V,则图像实际上已正确保存在剪贴板上,但是我的img变量返回None,这意味着ImageGrab.grabclipboard()无法正常工作.有什么想法吗?

When I run this, I notice that if I ctrl-V , the image is actually correctly saved on the clipboard, but my img variable returns None, meaning ImageGrab.grabclipboard() is somehow not working. Any ideas?

推荐答案

在这里,我有一个可能对您有所帮助的解决方案.

Here I have a solution which might help you.

import excel2img
excel2img.export_img("example.xlsx/example.csv","image.png/image.bmp","sheet!B2:H22")

这对我来说很好.

这篇关于Python将Excel工作表范围导出为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆