以插入远程图片为例子
from fake_useragent import UserAgent
fixed_size = 36 # 固定size为36
name = "test.xlsx"
url = "https://xxx/xxx.png"
workbook = xlsxwriter.Workbook(name)
worksheet = self.workbook.add_worksheet()
ua = UserAgent()
headers = {
'User-Agent': ua.random,
}
content = requests.get(url, headers=headers).content
image_data = io.BytesIO(content)
img = Image.open(image_data)
print("尺寸:",img.size)
x = float(fixed_size / img.size[0]) # 因为测试图片长和宽相等,只计算一边
self.worksheet.insert_image(f'A{row}', url, {'x_scale': x, 'y_scale': x, 'image_data': image_data,'valign': 'vcenter', 'align': 'center'})