zh648990 发表于 2021-7-18 13:10

求助大佬 Python pandas 怎么把图片写入xlsx?

本帖最后由 zh648990 于 2021-8-3 13:54 编辑

图片不下载到本地 直接把网络图片 写入表格?

UPC 发表于 2021-7-18 14:31

方法:https://xlsxwriter.readthedocs.io/worksheet.html#insert_image


示例代码:
##############################################################################
#
# An example of inserting images into a worksheet using the XlsxWriter
# Python module.
#
# Copyright 2013-2021, John McNamara, jmcnamara@cpan.org
#
import xlsxwriter


# Create an new Excel file and add a worksheet.
workbook = xlsxwriter.Workbook('images.xlsx')
worksheet = workbook.add_worksheet()

# Widen the first column to make the text clearer.
worksheet.set_column('A:A', 30)

# Insert an image.
worksheet.write('A2', 'Insert an image in a cell:')
worksheet.insert_image('B2', 'python.png')

# Insert an image offset in the cell.
worksheet.write('A12', 'Insert an image with an offset:')
worksheet.insert_image('B12', 'python.png', {'x_offset': 15, 'y_offset': 10})

# Insert an image with scaling.
worksheet.write('A23', 'Insert a scaled image:')
worksheet.insert_image('B23', 'python.png', {'x_scale': 0.5, 'y_scale': 0.5})

workbook.close()

ymhld 发表于 2021-7-19 14:18

https://zhuanlan.zhihu.com/p/212187337
页: [1]
查看完整版本: 求助大佬 Python pandas 怎么把图片写入xlsx?