Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用openpyxl在excel中查找图像并删除图像_Excel_Python 3.x_Image_Openpyxl - Fatal编程技术网

使用openpyxl在excel中查找图像并删除图像

使用openpyxl在excel中查找图像并删除图像,excel,python-3.x,image,openpyxl,Excel,Python 3.x,Image,Openpyxl,我有一个excel,我在其中使用openpyxl执行多项任务,比如读取和修改单元格中的数据。有一个图像和形状存在于同一个excel中,我正试图将其删除/删除,但我找不到任何模块来实现它。我可以添加图像但不能删除。是否有任何可能的方法从openpyxl中删除图像 openpyxl.reader.drawings.find_图像尝试使用此模块,但不确定其实现 for image in sheet._images: print(image) 上面给出了您上面提到的图像列表,然后您可以删除要删

我有一个excel,我在其中使用openpyxl执行多项任务,比如读取和修改单元格中的数据。有一个图像和形状存在于同一个excel中,我正试图将其删除/删除,但我找不到任何模块来实现它。我可以添加图像但不能删除。是否有任何可能的方法从openpyxl中删除图像

openpyxl.reader.drawings.find_图像尝试使用此模块,但不确定其实现

for image in sheet._images:
    print(image)
上面给出了您上面提到的图像列表,然后您可以删除要删除的图像的索引

del wb['worksheet']._images [1]
[1] 作为要删除的图像的示例索引,一如既往,不要忘记保存

wb.save('wb.xlsx')
然后应删除该图像

这是我的第一个答案,所以请给我一些建议

上面给出了您上面提到的图像列表,然后您可以删除要删除的图像的索引

del wb['worksheet']._images [1]
[1] 作为要删除的图像的示例索引,一如既往,不要忘记保存

wb.save('wb.xlsx')
然后应删除该图像


这是我的第一个答案,所以请给我一些建议

我也有同样的问题,我可以删除所有这样的图像

sheet._images = []
images = []
for sheet in wb:     
    for image in sheet._images:
        if image.path[-3:] !="png":
            images.append(image)
            
    sheet._images =   images
但在我的例子中,我不得不删除所有的png文件,所以我这样解决了

sheet._images = []
images = []
for sheet in wb:     
    for image in sheet._images:
        if image.path[-3:] !="png":
            images.append(image)
            
    sheet._images =   images

我有同样的问题,我可以删除像这样的所有图像

sheet._images = []
images = []
for sheet in wb:     
    for image in sheet._images:
        if image.path[-3:] !="png":
            images.append(image)
            
    sheet._images =   images
但在我的例子中,我不得不删除所有的png文件,所以我这样解决了

sheet._images = []
images = []
for sheet in wb:     
    for image in sheet._images:
        if image.path[-3:] !="png":
            images.append(image)
            
    sheet._images =   images