从url中插入图片到openpyxl [英] Insert an image from url in openpyxl
本文介绍了从url中插入图片到openpyxl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将URL中的图像插入到xlsx文件中.我怎么用openpyxl做到这一点?我检查了文档,但没有显示如何从URL插入图像.
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.
推荐答案
Openpyxl
中没有内置功能可通过URL插入图像.您需要为python使用Http客户端模块.(例如: urllib
)
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')
您没有正确搜索,对吗?
You didn't search properly, did you?
这篇关于从url中插入图片到openpyxl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文