如何使用XLSWRITER从URL (http)插入图像?这是来自文档:

worksheet.insert_image('B2', 'python.png')
.

worksheet1.insert_image('B10', '../images/python.png')
.

但这仅适用于文件路径。我想从Web服务器添加来自URL的图像。你可以帮忙吗?

有帮助吗?

解决方案

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')
.

其他提示

# 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://xlsxwriest.readthedocs.io/example_images_bytesio.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top