从Excel复制图像并使用python保存 [英] Copy Image from Excel and Save it using python

查看:526
本文介绍了从Excel复制图像并使用python保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从名为Inputs_v3的Excel和名为Inputs的工作表中复制图像并保存.代码如下.

I am trying to copy an image from an excel named Inputs_v3 and sheet named Inputs and save. The code is as follows`

import win32com.client as win32       
from PIL import ImageGrab 
from xlrd import open_workbook   
import os

excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
r.CopyPicture()

im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')

`错误如下

'Attribute error: 'Sheet' object has no attribute 'CopyPicture''

请提出我在哪里做错了.谢谢!

Please suggest where I am doing wrong.Thanks in advance

推荐答案

使用一个名为excel2img的python库.在一行中,您可以从任何Excel文件中截取屏幕截图

Use a python library called excel2img. In one line you can take a screenshot from any excel file

import excel2img
excel2img.export_img("Excel File Full Path", "Target Image full Path", "Excel SheetName", None)

,您还可以识别特定的单元格范围.

and you can identify a specific cells range as well.

import excel2img
excel2img.export_img("test.xlsx", "test.bmp", "", "Sheet2!B2:C15")

我希望这会有所帮助.

这篇关于从Excel复制图像并使用python保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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