Watermarking is one of the common ways of protecting documents from unauthorized usage. More often, a watermark defines the ownership of the copyrighted content. In accordance with that, this article covers how to perform watermarking in Excel files programmatically. Particularly, you will learn how to add watermark to an Excel worksheet using Python.
Python API to Add Watermarks to Excel Worksheets
Aspose.Cells for Python via Java is a spreadsheet manipulation API that lets you create, modify or convert Excel files. We will use it to add watermark to the Excel worksheets. You can download the API or install it using the following pip command.
pip install aspose-cells
Add a Watermark to Excel Worksheet in Python
The following are the steps to add a watermark in an Excel worksheet using Python.
- First, load the Excel file using Workbook class by providing its path.
- Get reference of the Worksheet to which you want to add the watermark.
- Create a watermark by adding a new Shape to the worksheet and set the its text and properties.
- Set Shape.setLocked(boolean) property to true to lock the watermark.
- Set other lock types using Shape.setLockedProperty(ShapeLockType, boolean) method.
- Finally, save the updated Excel file using Workbook.save(String) method.
The following code sample shows how to add a watermark to an Excel worksheet.
Output
The following is the screenshot of the Excel worksheet after adding the watermark.
Get a Free License
You can use Aspose.Cells for Python via Java without evaluation limitations using a temporary license.
Conclusion
Watermarks are extensively used to prevent the illegal usage of copyrighted Excel files. Accordingly, in this article, you have learned how to add watermark to Excel worksheets using Python. You can also explore other features of Aspose.Cells for Python via Java using the documentation. In case you would have any queries, you can post on our forum.