我可以使用python中的xlwt
模块的insert_bitmap
命令插入bmp图像,使用以下代码:
import xlwt
from PIL import Image
book = xlwt.Workbook()
sheet3 = book.add_sheet('diagrams')
Image.open('violations.png').convert("RGB").save('violations.bmp')
sheet3.insert_bitmap('violations.bmp',5,13)
book.save('simple.xls')
这是正确地将bmp图像插入到工作表中,但我担心bmp图像大约是3MB,如果没有明显的质量损失,我无法压缩它。
在unix中有没有办法将jpeg图像插入到工作表中?
从代码来看,xlwt似乎只支持24位位图图像。
Python模块可以插入PNG图像(或JPEG或位图)。下面是一个例子:
输出:
有关详细信息,请参见relevant section of the docs。
从 http://xlsxwriter.readthedocs.org/en/latest/example_images.html
如果需要在一次插入中偏移和缩放图像:
我花了一秒钟才弄明白,以为这样可以节省别人的时间
相关问题 更多 >
编程相关推荐