使用python复制图像时,图像在Excel文档中消失 [英] Images dissapear in excel documents when copying them with python

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

问题描述

import openpyxl

def factuur():
    wb = openpyxl.load_workbook('factuurvoorbeeld1.xlsx')
    Blad1 = wb.active
    Blad1['K7'] = 'logo.png'
    Blad1['E22'] = factuurNr.get()
    Blad1['E23'] = datum.get()
    Blad1['E24'] = debNr.get()
    Blad1['E25'] = locatie.get()
    wb.save('{}.xlsx'.format(factuurNr.get() + ',' + debNr.get()))

我正在尝试编写一个使用简单的GUI和输入字段自动填写Excel文档的应用程序.问题是,每当python复制基本Excel文件(每个文档中包含个人信息的文件以及一张图像)时,该图像就会消失.你们中有人知道该怎么做吗?我正在使用Python 3.5.

I'm trying to program an application that automatically fills in Excel documents by using a simple GUI and entry fields. The problem is, everytime python makes a copy of the base Excel file (The one with personal information that is in every document along with one image), the image dissappears. Do any of you guys know what to do about this? I'm using Python 3.5.

我尝试过的事情:1)多个Excel模块2)关于在excel中编写代码的东西(不确定我是否正确执行了此操作)

Things I have tried: 1) multiple Excel modules 2) Something about writing code in excel(Not sure if I did this correctly though)

很抱歉,我的描述很糟糕,我真的不知道该如何描述这种东西.如果您想了解更多,只需在评论中留下一个问题,我会尽可能地进行检查.

Sorry for my horrible description, I'm don't really know how to describe this kind of stuff. If you want to know more, just leave a question in the comments, I will check as often as i can.

Blad1 = Excel文档的第一张纸.

Blad1 = The first sheet of the excel document.

推荐答案

不幸的是,openpyxl目前不支持图像,请参见官方文档: https://openpyxl.readthedocs.io/en/default/usage.html

Unfortunately openpyxl does not support images at this time, see official documentation: https://openpyxl.readthedocs.io/en/default/usage.html

openpyxl当前无法读取Excel文件中的所有可能项目因此,如果图像和图表已经存在,则会从现有文件中丢失打开并以相同的名称保存.

openpyxl does currently not read all possible items in an Excel file so images and charts will be lost from existing files if they are opened and saved with the same name.

因此,当您打开模板文件时,不会读取图像,因此不会将其保存在新文件中.

So when you open the template file, the images are not read, thus not saved in the new file.

如果您按照以下文档再次使用openpyxl插入图片,则可能会起作用: https://openpyxl.readthedocs.io/en/default/usage.html#inserting-an-image

It might work if you insert the image again with openpyxl, by following the doc here: https://openpyxl.readthedocs.io/en/default/usage.html#inserting-an-image

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

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