How to set a watermark using xlsxwriter engine

Viewed 52

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.

1 Answers

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.

Related