python - 使用Python将图像添加到excel中的注释中
问题描述
我想通过python将本地驱动器中可用的jpeg图片包含在excel中的注释中。我怎样才能做到这一点?
在单元格中插入图像的代码
import xlsxwriter
workbook = xlsxwriter.Workbook('images.xlsx')
worksheet = workbook.add_worksheet()
worksheet.insert_image('A2', 'image.jpg')
workbook.close()
写评论的代码
import xlsxwriter
workbook = xlsxwriter.Workbook('comments1.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('D5', 'Hello')
worksheet.write_comment('D5', "This is comment")
workbook.close()
解决方案
这有帮助吗?我在文档中找到了这个
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()
推荐阅读
- php - 以不区分大小写的方式搜索文件?
- python - 使用Python定义一个返回一段时间内最常用词的函数
- swagger - 未应用 Swagger OAS 3.0 中的独有最小值
- react-native - 当应用程序从后台返回时卡在 Android 启动屏幕上
- javascript - svg:rect 和 rect 的区别
- excel - 当协调组合的数量未知时,协调两个数据集/集合
- visual-studio - 如何将 ZeroMQ 导入 Unity 引擎?
- javascript - 用 momentjs 和 range 计算加班时间
- java - Java 输出下划线的逻辑错误
- python - os.walk() 错误 - 太多值无法解压