python - 使用 LibreOffice 打开时图像不显示在标题中

标签 python xlsx xlsxwriter libreoffice-calc

我需要使用 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 运行它时得到的输出:

enter image description here

也许您使用的是旧版本的 XlsxWriter。按如下方式检查您的版本:

python -c "import xlsxwriter; print(xlsxwriter.__version__)"

至少应该是0.6.0,当前版本是0.9.2。

关于python - 使用 LibreOffice 打开时图像不显示在标题中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38323022/

相关文章:

python - Numpy:使用矩阵切片体积

javascript - 如何使用 ExcelJS 将 xlsx 写入浏览器中的文件?

r - 使用 "xlsx"包读取时间戳时出错

python - 使用循环将大数据写入 Excel 列单元格

python - 如何使用 xlsxwriter 在 python 中格式化一系列单元格

python - "Cannot find installed version of python-django or python3-django"运行 celeryworker 时

python - 如何覆盖 Python Dataclass 'asdict' 方法

python - 值错误: could not convert string to float: 'lisans' in Python

javascript - 如何使用 Node js 中的 xlsx/sheetjs 包在现有 xlsx 文件中创建新工作表?

python-3.x - `xlsxwriter` 除非更改颜色,否则线条透明度不起作用