gpt4 book ai didi

python - 如何使用 openpyxl 查找包含图像的单元格

转载 作者:行者123 更新时间:2023-12-01 03:01:43 25 4
gpt4 key购买 nike

我正在循环遍历工作簿中的每个单元格。由于某种原因,当 openpyxl 迭代包含图像的工作表时,该图像将被删除。如何解决这个问题?

我正在寻找一种方法来传递具有图像的单元格。

我不处于 read_only 模式,并且也不希望处于这种模式,因为我正在对工作表进行修改。

这样的东西对我来说最有用:

if cell is image:
pass

最佳答案

https://pypi.org/project/openpyxl-image-loader/

from openpyxl import load_workbook
from openpyxl_image_loader import SheetImageLoader

# Load your workbook and sheet as you want, for example
wb = load_workbook('path_to_file.xlsx')
sheet = wb['required_sheet']

# Put your sheet in the loader
image_loader = SheetImageLoader(sheet)

# And get image from specified cell
image = image_loader.get('A3')

# Image now is a Pillow image, so you can do the following
image.show()

# Ask if there's an image in a cell
if image_loader.image_in('A4):
print("Got it!")

关于python - 如何使用 openpyxl 查找包含图像的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43748023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com