gpt4 book ai didi

Python Excelwriter (xlsxwriter) 从 URL 插入图像

转载 作者:行者123 更新时间:2023-11-30 23:23:18 25 4
gpt4 key购买 nike

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

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

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

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

最佳答案

# 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

关于Python Excelwriter (xlsxwriter) 从 URL 插入图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24055175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com