Insert an image from url in openpyxl

你说的曾经没有我的故事 提交于 2021-02-07 10:55:29

问题


I would like to insert an image from URL into the xlsx file. How could I do that with openpyxl? I checked the documentation but not shows how to insert an image from URL.


回答1:


There is no built-in function in Openpyxl to insert images through URLs. You'll need to use an Http client module for python.(example:urllib)

import openpyxl
from openpyxl.writer.excel import save_virtual_workbook
from openpyxl.drawing.image import Image
import PIL
import io
import urllib3

wb = openpyxl.Workbook()
ws = wb.active
r = 1
ws['A1'] = 'test'
http = urllib3.PoolManager()
r = http.request('GET', 'http://myridia.com/assets/images/logo.png')
image_file = io.BytesIO(r.data)
img = Image(image_file)
ws.add_image(img, 'A2')

Source: Insert image from URL in openpyxl.

You didn't search properly, did you?



来源:https://stackoverflow.com/questions/42875353/insert-an-image-from-url-in-openpyxl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!