Python模板化处理Word

电脑技术 电脑技术 1243 人阅读 | 0 人回复 | 2022-04-14

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
doc = DocxTemplate('examples/sample.docx')

context = {
'table': Table(data=[['this is the first cell of the first row', 'this is the second cell of the first row'],
['the second row', 'etc'],
['etc', 'etc]],
headers=['header 1', 'header 2']),
'image': Image('pigeon.jpg')
'html': HTML(<p><strong>bold</strong>-notbold</p><ul><li>hop</li><li>la</li><li>kee</li></ul>")
'text': 'some text',
}

doc.render_and_save('generated.docx', context)
doc.render_and_save('generated.pdf', context, format='pdf')
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则