2014-06-05 3 views
1

(http)과 xlswriter의 이미지 을 어떻게 삽입합니까? 이 문서에서입니다 :Python Excel Writer (xlswriter) URL에서 이미지 삽입

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

또는

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

그러나 이것은 단지 파일 경로입니다. 웹 서버의 URL에서 이미지를 추가하고 싶습니다. 도울 수 있니?

+0

당신은 당신이 이미지에 링크하여하고 싶은 말은? –

+0

먼저 임시 폴더에 다운로드 할 수 있습니까? –

+0

Tim : urllib.request.urlopen (url) .read()로 데이터를 가져올 수 있지만 그 이후에는 무엇을 할 수 있는지 알지 못합니다. Rickard : 아니, URL에서 삽입하는 것뿐입니다. – Rictrunks

답변

1
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') 
1
# 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