Sid*_*han 3 python unix excel xlwt
我可以使用以下代码在python中使用模块的insert_bitmap命令插入bmp图像xlwt:
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')
Run Code Online (Sandbox Code Playgroud)
这是正确地将bmp图像插入到工作表中,但我担心的是bmp图像大约是3MB,我无法压缩它而没有明显的质量损失.
有没有办法将jpeg图像插入到unix中的工作表中?
从查看代码看起来xlwt只支持24位位图图像.
所述XlsxWriter Python模块可以插入PNG图像(或JPEG或位图).这是一个例子:
from xlsxwriter.workbook import Workbook
# Create an new Excel file and add a worksheet.
workbook = 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')
workbook.close()
Run Code Online (Sandbox Code Playgroud)
输出:
