问题
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