Python Excel Writer (XLSWRITER) inserte imagen de URL
-
23-12-2019 - |
Pregunta
¿Cómo puedo insertar una imagen de URL (http) con xlswreiter?Esto es de la documentación:
worksheet.insert_image('B2', 'python.png')
o
worksheet1.insert_image('B10', '../images/python.png')
Pero esto es solo para la ruta de archivo.Quiero agregar imagen de URL desde un servidor web.¿Puedes ayudar?
Solución
url = "http://abcdef.com/picture.jpg"
data = urllib.request.urlopen(url).read()
file = open("image.jpg", "wb")
file.write(data)
file.close()
worksheet.insert_image('B2', 'image.jpg')
Otros consejos
# Read an image from a remote url.
url = 'https://raw.githubusercontent.com/jmcnamara/XlsxWriter/' + \
'master/examples/logo.png'
image_data = BytesIO(urllib2.urlopen(url).read())
# Write the byte stream image to a cell. Note, the filename must be
# specified. In this case it will be read from url string.
worksheet.insert_image('B2', url, {'image_data': image_data})
http://xlsxwriter.readthedocs.io/example_images_bytesio.html
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow