如何使用XLSXWriter引擎设置水印

发布于 2025-02-10 19:50:43 字数 575 浏览 3 评论 0原文

我想为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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴梦长久 2025-02-17 19:50:43

当您通过这样的标头图像添加水印(这是做到这一点的最佳方法)时,在正常视图中不可见图像。仅当您切换到页面布局视图或打印预览时,才会看到它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文