0

我正在尝试使用 python 和 openpyxl 的 add_image 函数创建一个脚本,它将调整大小的照片添加到单元格中,为此我使用以下代码:

from PIL import Image
from openpyxl import load_workbook
from openpyxl import Workbook

wb = load_workbook('file.xlsx')
ws = wb.active

max_row = ws.max_row

########## SET DIMENSIONS FOR 'F' cells#######
ws.column_dimensions['F'].width=200 
for x in range (2,max_row+1):
    ws.row_dimensions[x].height=200
##############################################
img = Image.open(file)
bound_width_height = (195, 150)
img.thumbnail(bound_width_height, Image.ANTIALIAS)
nimg = openpyxl.drawing.image.Image(img)
ws.add_image(nimg,'F3')

wb.save('test.xlsx')
print('done!')

但是当我查看test.xlsx文件时,我看到了This image cannot curently be displayed.

结果: https ://imgur.com/a/mjgL4hn

任何想法为什么?

4

0 回答 0