Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Excel编写器(xlswriter)从URL插入图像_Python_Excel_Python 3.x_Urllib_Xlsxwriter - Fatal编程技术网

Python Excel编写器(xlswriter)从URL插入图像

Python Excel编写器(xlswriter)从URL插入图像,python,excel,python-3.x,urllib,xlsxwriter,Python,Excel,Python 3.x,Urllib,Xlsxwriter,如何使用xlswriter从URL(http)插入图像?这来自文件: worksheet.insert_image('B2', '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.c

如何使用xlswriter从URL(http)插入图像?这来自文件:

worksheet.insert_image('B2', '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')


你的意思是要热链接到图像?是否可以先将其下载到临时文件夹?蒂姆:我可以使用urllib.request.urlopen(url.read())获取其数据,但之后,我不知道该怎么办。里卡德:不,只是从URL插入。你的意思是你想热链接到图像?可以先下载到一个临时文件夹吗?蒂姆:我可以用urllib.request.urlopen(URL.read()获取它的数据,但在那之后,我不知道该怎么办。里卡德:不,只是从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})