Spire.Office Knowledgebase Page 42 | E-iceblue

Python: Add a Watermark to Excel

2024-07-23 01:10:21 Written by Koohji

While watermarks are a common design element used in many types of documents to convey ownership, confidentiality, or branding, Microsoft Excel does not provide a built-in watermark feature. However, there are workaround methods to achieve a watermark effect in Excel spreadsheets.

One approach is to add an image to the header or footer of the worksheet, and another approach is to add an image to a worksheet as the background. In this article, you will learn how to add a header or background image watermark to Excel in Python using Spire.XLS for Python.

Install Spire.XLS for Python

This scenario requires Spire.XLS for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip command.

pip install Spire.XLS

If you are unsure how to install, please refer to this tutorial: How to Install Spire.XLS for Python on Windows

Header vs Background Image Watermarks

Header Image Watermark:

Advantages:

  • The watermark is preserved on the printed sheet, ensuring it appears in the final output.

Disadvantages:

  • The watermark is invisible under the "Normal" view mode in Excel, only becoming visible in "Page Layout" or "Page Break Preview" views.
  • To centrally position the watermark graphic on the Excel page, you need to carefully adjust the white margins, especially on the top and left sides of the image.

Background Image Watermark:

Advantages:

  • The watermark image covers the entire worksheet area, providing a consistent background appearance.

Disadvantages:

  • The watermark is not preserved on the printed sheet, meaning it will not appear in the final printed output.

Add a Watermark to Excel Using a Header Image in Python

Spire.XLS for Python offers the PageSetup class to control various settings related to the appearance and layout of the printed worksheet. Under this class, you can find the CenterHeader and CenterHeaderImage properties, allowing you set an image for the center section of the header.

Here are the steps to add a header image watermark to Excel using Python.

  • Create a Workbook object.
  • Load an Excel document from a give file path.
  • Load an image while initialing the Stream class.
  • Get a specific worksheet from the workbook.
  • Add an image field to the header center by setting Worksheet.PageSetup.CenterHeader property to "&G".
  • Apply the image to the header center through Worksheet.PageSetup.CenterHeaderImage property.
  • Save the workbook to a different Excel file.
  • Python
from spire.xls import *
from spire.xls.common import *

# Create a Workbook object
workbook = Workbook()

# Load an Excel document
workbook.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Input.xlsx")

# Load an image file
stream = Stream("C:\\Users\\Administrator\\Desktop\\confidential.png")

# Loop through all worksheets in the file
for i in range(workbook.Worksheets.Count):

    # Get a specific worksheet
    worksheet = workbook.Worksheets[i]

    # Add an image field to the header center
    worksheet.PageSetup.CenterHeader = "&G"

    # Add the image to the header center
    worksheet.PageSetup.CenterHeaderImage = stream

# Save the result file
workbook.SaveToFile("output/AddWatermark.xlsx", ExcelVersion.Version2016)

# Dispose resources
workbook.Dispose()

Python: Add a Watermark to Excel

Add a Watermark to Excel Using a Background Image in Python

The PageSetup class provides the BackgroundImage property to get or set the image for the background. Below are the steps to add a background image watermark to Excel using Python.

  • Create a Workbook object.
  • Load an Excel document from a give file path.
  • Load an image while initialing the Stream class.
  • Get a specific worksheet from the workbook.
  • Apply the image to the worksheet as the background through Worksheet.PageSetup.BackgroundImage property.
  • Save the workbook to a different Excel file.
  • Python
from spire.xls import *
from spire.xls.common import *

# Create a Workbook object
workbook = Workbook()

# Load an Excel document
workbook.LoadFromFile("C:\\Users\\Administrator\\Desktop\\Input.xlsx")

# Load an image file
stream = Stream("C:\\Users\\Administrator\\Desktop\\sample-background.png")

# Loop through all worksheets in the file
for i in range(workbook.Worksheets.Count):

    # Get a specific worksheet
    worksheet = workbook.Worksheets[i]

    # Set the image as the background of the worksheet
    worksheet.PageSetup.BackgoundImage = stream

# Save the result file
workbook.SaveToFile("output/AddWatermark.xlsx", ExcelVersion.Version2016)

# Dispose resources
workbook.Dispose()

Python: Add a Watermark to Excel

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Excel workbooks have become one of the most commonly used spreadsheet formats. Efficiently managing, editing, and sharing Excel files is a key competency in both personal and professional settings. Editing Excel files and converting them to PDF, CSV, OTS, etc. formats online offers significant advantages. One of the primary benefits is the elimination of reliance on local software installations. Users only need a web browser, making the process accessible from any device, be it a PC or a mobile phone.

Furthermore, online tools facilitate seamless collaboration. Multiple users can access and edit the same document simultaneously, promoting teamwork and keeping information up-to-date. Converting Excel files to PDF online also ensures that documents are universally accessible and secure, maintaining formatting and integrity across different platforms and devices.

This article will show how to edit Excel files and convert Excel files to other formats online with Spire.Cloud.Excel library, realizing cross-platform and efficient online Excel file editing.

Get Spire.Cloud.Excel Online Editor

Spire.Cloud.Excel is a powerful online Excel viewer and editor designed for viewing, creating, editing, and collaborating on Excel documents in HTML5-compliant browsers. It also supports converting spreadsheets to PDF, PDF/A, CSV, and OTS formats.

Spire.Cloud.Excel is currently available on Windows and Linux. Download Spire.Cloud.Excel and follow the guide below to install it on the server:

After installing Spire.Cloud.Excel on your server, you can try out the features of the editor via port 3000 or integrate the editor into your HTML pages via JavaScript.

Edit Excel Files and Convert Them to PDF and Other Formats Online

Load and Modify Excel Workbooks Online

Spire.Cloud.Excel supports uploading a variety of spreadsheet formats for viewing, editing, and conversion, including XLS, XLSX, XLSM, XLSB, XLT, XLTX, XLTM, CSV, ODS, UOS, ET, and ETT.

Spreadsheet files will be automatically converted to Open XML format after uploading so that they can be quickly viewed and edited in the online editor.

Steps to upload an Excel document and edit it online:

1. Open the product home page and select the Upload button.

Edit Excel Files and Convert Them to PDF and Other Formats Online

2. Select a file and upload it. Wait for the format conversion to complete and select Edit.

Edit Excel Files and Convert Them to PDF and Other Formats Online

3. Various modifications and creations can be made to the document within the editor, including cell content editing, formatting, image insertion, page setup, data analysis, chart insertion, worksheet creation, pivot table generation, commenting, and even document printing.

Online editor:

Edit Excel Files and Convert Them to PDF and Other Formats Online

Print spreadsheets:

Edit Excel Files and Convert Them to PDF and Other Formats Online

4. The editor will save changes to the document every 10 minutes, or you can click "File" > "Save" to apply changes manually.

Edit Excel Files and Convert Them to PDF and Other Formats Online

5. When multiple people edit the same document online at the same time, the document changes will be synchronized in real-time, making it easy for users to get content updates in a timely manner and get an efficient collaborative editing experience.

Edit Excel Files and Convert Them to PDF and Other Formats Online

Create a New Excel Workbook Online

In addition to uploading Excel files for viewing and editing, users can also use Spire.Cloud.Excel to create new Excel files online. Below are the steps to create a new Excel file online using Spire.Cloud.Excel:

1. Open the main page and select Create Spreadsheet. When creating, users can also choose "Create a file filled with sample content" to create an Excel document with sample content.

Edit Excel Files and Convert Them to PDF and Other Formats Online

2. Once the document is created, users can edit it in the pop-up online editor.

Edit Excel Files and Convert Them to PDF and Other Formats Online

Convert Excel Files to PDF, PDF/A, OTS, and CSV Online

Spire.Cloud.Excel also supports exporting documents to multiple formats for sharing, presentations, and more. Currently, it supports exporting spreadsheets to XLSX, PDF, CSV, XLTX, PDF/A, and OTS formats to meet various document usage requirements.

Steps for converting Excel files to formats like PDF and OTS:

1. Upload or create an Excel document.

2. After editing, choose "File" > "Download as" in the toolbar.

Edit Excel Files and Convert Them to PDF and Other Formats Online

3. Choose a file format to save the document.

Edit Excel Files and Convert Them to PDF and Other Formats Online

Conclusion

This article demonstrates how to use Spire.Cloud.Excel to preview, edit, print, and convert Excel files to PDF and other formats online. The API also supports many other online document-processing features. Use Spire.Cloud.Excel to create your online document editing projects or embed them into existing web pages for easier and more efficient online spreadsheet processing capabilities.

With the advent of cloud-based document management tools, teams can now work together in real-time, enhancing efficiency and productivity. When collaboratively editing a document online, the ability to communicate directly within the document allows team members to instantly share or discuss ideas, ask questions, and provide feedback.

This article will guide you on how to chat with your co-editors in real-time in the Spire.Cloud.Office document editor.

Spire.Cloud.Office Document Editor

Spire.Cloud.Office is a feature-rich HTML-5 based document editor component that can be easily integrated into web applications. With the document editor component, your end-users can view, create, edit, and collaborate on diverse document types within a web browser.

To utilize the services offered by Spire.Cloud.Office, you will need to first install it on your system.

After the installation is complete, you can integrate Spire.Cloud.Office editor in your own web application or visit the example application hosted on port 3000 to explore the editor's functionalities.

The example page offers options to upload existing documents or create new ones. Spire.Office.Cloud supports loading DOC/DOCX, XLS/XLSX, and PPT/PPTX files, and exporting files to DOCX, XLSX, and PPTX formats.

Chat with Co-Editors While Editing a Document Online

Chat with Co-Editors Using the Editor Chat Feature

Spire.Cloud.Office allows co-editing a document with multiple users at the same time, and it also integrates the chat feature in the editor. To chat with your collaborators in real-time, follow the steps below:

1. Open the document you're working on with your collaborators by clicking on the computer icon in the "Editor" section.

Chat with Co-Editors While Editing a Document Online

2. After opening in the editor, click the "Chat" button under the "Review" tab to initiate a chat with your coworkers.

Chat with Co-Editors While Editing a Document Online

3. When you click the button, a chat sidebar will appear on the left side of the document. The users who are in the document at the moment will be displayed in the top area.

If you want to chat with them, type message in the text box and then press the "Send" button.

Chat with Co-Editors While Editing a Document Online

4. Your co-editors can also type messages in the same way to chat with you. All messages you send or receive will be displayed in the chat sidebar in real time.

Chat with Co-Editors While Editing a Document Online

Chat with Co-Editors Using the Comments Feature

Another way to communicate with your collaborators is to use the comments feature. With the ability to comment in real-time, team members can quickly respond to each other's suggestions or questions. The following are the steps to chat with your collaborators through comments:

1. Select a specific part where you want add comments, and then click the "Comments" icon under the "Review" tab.

Chat with Co-Editors While Editing a Document Online

2. After clicking, a comment box will appear. Type your comment in the text box and click the "Add" button.

Chat with Co-Editors While Editing a Document Online

3. The part where you've attached a comment will be highlighted and when your collaborators click on the text, they will see the comment. To reply to the comment, first click the "Add reply".

Chat with Co-Editors While Editing a Document Online

Then type replies in the text box and click the "Reply" button.

Chat with Co-Editors While Editing a Document Online

4. By inserting and replying to comments in real time, you and your co-editors can instantly communicate ideas, suggestions about the document.

Chat with Co-Editors While Editing a Document Online

Note: In the first example, the chat history won't be saved when you close the document. However, the comments in the second example can be saved with the document. Therefore, in addition to real-time comments, users will also be able to view and reply to comments at any time afterwards.

To view all comments in a document, click the "Comments" text under the "Review" tab.

Chat with Co-Editors While Editing a Document Online

page 42