Python Excel Writer (xlswriter) URL에서 이미지 삽입
-
23-12-2019 - |
문제
XLSwriter가있는 URL (HTTP)에서 이미지 을 어떻게 삽입 할 수 있습니까?이것은 문서에서 다음과 같습니다.
worksheet.insert_image('B2', 'python.png')
.
또는
worksheet1.insert_image('B10', '../images/python.png')
.
그러나 이것은 파일 경로에만 해당됩니다.웹 서버에서 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://xlsxwriter.readthedocs.io/example_images_bytesio.html
제휴하지 않습니다 StackOverflow