我需要使用 Python XlsxWriter 创建自定义发票,我需要在其中创建带有公司 Logo 的自定义抬头。生成的工作簿必须使用 LibreOffice 打开,而不是 Excel。
使用 here 中的示例.我的代码是:
#!/usr/bin/env python
try:
import xlsxwriter
except ImportError as e:
print e
exit()
workbook = xlsxwriter.Workbook('tmp.xlsx')
preview = 'Select Print Preview to see the header and footer'
# Insert a header image.
#
worksheet1 = workbook.add_worksheet('Simple')
header1 = '&L&G'
footer1 = '&LHere is some left aligned text.'
worksheet1.set_header(header1, {'image_left': 'logo.png'})
worksheet1.set_footer(footer1)
worksheet1.set_margins(top=1.3)
# Insert an image.
worksheet1.write('A2', 'Insert an image in a cell:')
worksheet1.insert_image('B2', 'logo.png')
worksheet1.set_column('A:A', 50)
worksheet1.write('A1', preview)
workbook.close()
虽然我的 Logo 可以插入到 B2 单元格中,但在使用 LibreOffice 打开时,我的图像无法在页眉中找到。该图像在 Excel 中显示应有的样子。
最佳答案
您的示例确实有效。这是我使用最新版本的模块和 Excel 2013 运行它时得到的输出:
也许您使用的是旧版本的 XlsxWriter。按如下方式检查您的版本:
python -c "import xlsxwriter; print(xlsxwriter.__version__)"
至少应该是0.6.0,当前版本是0.9.2。
关于python - 使用 LibreOffice 打开时图像不显示在标题中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38323022/