小编Ale*_*aPM的帖子

如何更改图像的位置:使用 openpyxl 在 Excel 中“移动和调整单元格大小”

在此处输入图片说明

如何使用 Openpyxl 使用 Python 选择此图像属性?我需要这个,所以如果我过滤 Excel 文档,图像也会被过滤。

我调用了一个我做过的函数:insert_image(ws, url, cell_picture, 64, 66) ws 是我添加的工作表 url 是图像 cell_picture 单元格 64 和 66 的宽度和高度

我的功能是这样的:

def insert_image(ws, image_url, cell, width = 101, height= 129):

  # load image
    image_path = "image.jpg"
    try:
        urllib.request.urlretrieve(image_url, image_path)
        img = Image.open(image_path)
    except:
        print ('Picture ' + image_url + ' not found')
        return
    max_width, max_height = width , height

    cell_ratio = float(max_height) / max_width
    img_ratio = float(img.size[1])/img.size[0]

    if (cell_ratio<img_ratio):
        hpercent = (max_height/float(img.size[1]))
        wsize = int((float(img.size[0])*float(hpercent)))
        img = …
Run Code Online (Sandbox Code Playgroud)

excel image openpyxl

5
推荐指数
1
解决办法
1139
查看次数

标签 统计

excel ×1

image ×1

openpyxl ×1