简体   繁体   English

如何使用 python 将图像插入特定的 excel 文件单元格?

[英]How to insert images to specific excel file cells using python?

I need to create an excel file and add images to certain cells so in each row I add two images in A1 and B1.我需要创建一个 excel 文件并将图像添加到某些单元格,因此在每一行中,我在 A1 和 B1 中添加两个图像。 I need to do this for around 150 images by copying and pasting them?我需要通过复制和粘贴来对大约 150 张图像执行此操作吗?

Can someone tell me how to do that using python script automatically by just defining the images path and the excel file path and the number of the images in the folder?有人可以告诉我如何通过仅定义图像路径和 excel 文件路径以及文件夹中图像的数量来自动使用 python 脚本来做到这一点吗?

Using the xlsxwriter library使用 xlsxwriter 库

import xlsxwriter

# creates an excel sheet
workbook = xlsxwriter.Workbook('images.xlsx')
worksheet = workbook.add_worksheet()
worksheet.insert_image('B2', 'your-image-name.png')

workbook.close()

See the xlsxwriter docs for more details有关更多详细信息,请参阅xlsxwriter 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM