如何使用XLSXWriter引擎设置水印
我想为Excel文件设置水印,该文件将由代码生成。
我尝试过set_header()函数,但是它没有在生成的下载文件中显示水印。我尝试过的代码是:
writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter')
data.to_excel(writer, sheet_name='Download Sheet', startrow=2, startcol=0 , header=None, index = False)
worksheet = writer.sheets['Download Sheet']
# worksheet.set_header('&C&G', {'image_center': 'logo.png'})
worksheet.set_header('&C&[Picture]', {'image_center': 'logo.png'})
即使是评论的代码行也没有起作用。使用
worksheet.set_background('logo.png')
将图像设置为整个页面,而无需任何水印。
I want to set a watermark to the excel file which will be generated by the code.
I have tried set_header() function, but it is not showing the watermark in the generated downloaded file. The code I have tried is:
writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter')
data.to_excel(writer, sheet_name='Download Sheet', startrow=2, startcol=0 , header=None, index = False)
worksheet = writer.sheets['Download Sheet']
# worksheet.set_header('&C&G', {'image_center': 'logo.png'})
worksheet.set_header('&C&[Picture]', {'image_center': 'logo.png'})
Even the commented line of code didn't worked. Using
worksheet.set_background('logo.png')
Sets the image to the whole page, without any watermark.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您通过这样的标头图像添加水印(这是做到这一点的最佳方法)时,在正常视图中不可见图像。仅当您切换到页面布局视图或打印预览时,才会看到它。
When you add a watermark via a header image like this (which is the best way to do it) the image isn't visible in the Normal view. You will only see it when you switch to Page Layout view, or Print Preview.