kwd*_*kwd 2 python unix libreoffice xlsxwriter
我想将图像添加到 xlsx 的标题中,但它在生成的文件上没有显示任何内容(我们的应用程序选择 .csv,然后使用 xlsxwriter 的 .py 文件转换为 .xlsx,然后使用 libreoffice 命令转换为 .pdf)
我们已经尝试过不同的图像格式和尺寸,但没有什么区别。
还尝试了库中的示例(https://xlsxwriter.readthedocs.io/example_headers_footers.html?highlight=set_header),但没有成功。
我们使用了worksheet.insert_image(),它添加了图像,但不在标题中。这是我们当前的结果: https: //ibb.co/QNXv8bM
我们希望将图像直接添加到标题上(也许使用 ),set_header()但到目前为止,我们尝试使用此方法尚未产生任何结果。当我们使用set_header()放置图像时,它在标题上什么也不显示。
这是我们正在使用的 python 文件的一部分:
def create_worksheet(workbook, data, image, p_header_text):
'''
Creates and formats worksheet
:param workbook: Main workbook
:type workbook: xlsxwriter.Workbook
:param data: dict with data to use in the worksheet
:type data: dict
data example:
data = {'headings': [head1, head2, ..., headn], 'rows': [[data1, ..., datan], ...]}
:return: Nothing
'''
worksheet = workbook.add_worksheet()
### Page Setup
worksheet.set_margins(top=1.4)
worksheet.set_landscape()
worksheet.hide_gridlines(2)
#worksheet.set_paper(9) # 9 = A4
worksheet.fit_to_pages(1, 0)
### Header and footer
header_text = p_header_text
#worksheet.set_header('&C&16&"Calibri,Bold"{}'.format(header_text))
worksheet.set_header('&L&G', {'image_left': '/home/reports/LTA-logo.jpg'})
worksheet.set_footer('&L&D&RPage &P of &N')
#worksheet.insert_image('A1', '/home/reports/LTA-logo.jpg', {'x_offset': 0, 'y_offset': 0})
#worksheet.set_header('&C&G', {'image_left': '/home/reports/LTA-logo.jpg'})
### Create table
create_table(worksheet, data)
Run Code Online (Sandbox Code Playgroud)
注意:worksheet.set_header('&C&16&"Calibri,Bold"{}'.format(header_text))工作正常,它显示标题上的文本。问题是当我们尝试将图像...
预期结果是使图像出现在标题中,与标题左对齐,如下图所示: https: //ibb.co/vQTytK2
注 2:出于商业原因(公司),我无法在打印屏幕上显示数据
它应该与 XlsxWriter 一起使用。&L您只需要使用左侧部分和中间部分以正确的方式构建格式字符串&C。
例如:
import xlsxwriter
workbook = xlsxwriter.Workbook('headers_footers.xlsx')
worksheet = workbook.add_worksheet('Image')
# Adjust the page top margin to allow space for the header image.
worksheet.set_margins(top=1.3)
worksheet.set_header('&L&[Picture]&C&16&"Calibri,Bold"Revenue Report',
{'image_left': 'python-200x80.png'})
workbook.close()
Run Code Online (Sandbox Code Playgroud)
&[Picture]请注意,我在示例中使用了更明确的方法,但&G效果也很好。
输出:
| 归档时间: |
|
| 查看次数: |
2481 次 |
| 最近记录: |