Logo

dev-resources.site

for different kinds of informations.

3 Easy Steps to Add Watermarks to Your Excel Document Using C#

Published at
8/13/2024
Categories
excel
csharp
documentprocessing
fileformats
Author
lucy_muturi
Author
11 person written this
lucy_muturi
open
3 Easy Steps to Add Watermarks to Your Excel Document Using C#

TL;DR: Adding a watermark boosts branding, confidentiality, protection, and visual appeal. Use Syncfusion’s Excel Library in C# to easily add watermarks: set up a .NET Core Console app, install the NuGet package, and apply the code to insert and save. For full details, check the documentation and GitHub demo.

A watermark in Excel is a faint background image or text that appears behind the content of a worksheet. It is used for branding, confidentiality, or to indicate the status of a document, such as Draft or Confidential. Watermarks do not interfere with the readability of the data and are often used to protect the document’s integrity.

The Syncfusion .NET Excel Library, also known as Essential XlsIO, is a robust tool that facilitates the smooth creation, reading, and editing of Excel documents using C#. It supports the creation of Excel documents from scratch, modification of existing Excel documents, data import and export, Excel formulas, conditional formats, data validations, charts, sparklines, tables, pivot tables, pivot charts, template markers, and much more.

This blog will explore the steps to insert a watermark into an Excel document using the Syncfusion .NET Excel Library and C#.

Note: Before proceeding, refer to the .NET Excel Library’s getting started documentation.

Steps to add a watermark to an Excel document using CSharp

Follow these steps to add watermarks to your Excel document using C# and .NET Excel Library:

  1. First, create a .NET Core Console app in Visual Studio, as shown in the following image.Create a .NET Core Console app in Visual Studio.
  2. Then, install the latest Syncfusion.XlsIO.NET.Core NuGet package to your app.Install Syncfusion.XlsIO NuGet package
  3. Adding a picture to the background as a watermark of the company’s logo or a relevant image will improve the document’s appearance. When you set a background picture to a worksheet, the picture is tiled so that it fills the whole screen repeatedly.The following code shows how to add a watermark to your Excel worksheet as a background image. The process will assume you already have the picture on your computer to use as a background image.
using Syncfusion.XlsIO;
using Syncfusion.Drawing;

namespace WaterMark
{
    class Program
    {
        public static void Main(string[] args)
        {
            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Xlsx;

                // Load an existing Excel file.
                FileStream inputStream = new FileStream(@"../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
                IWorkbook workbook = application.Workbooks.Open(inputStream);
                IWorksheet worksheet = workbook.Worksheets[0];

                // Insert image in the worksheet for watermark.
                FileStream imageStream = new FileStream(@"../../../Data/Watermark.png", FileMode.Open, FileAccess.Read);
                worksheet.PageSetup.BackgoundImage = new Image(imageStream);

                // Save the workbook as stream.
                FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.Write);
                workbook.SaveAs(outputStream);

                //Dispose streams.
                inputStream.Dispose();
                imageStream.Dispose();
                outputStream.Dispose();
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Refer to the following images.

Input Excel document

Adding a watermark to an Excel document using Syncfusion .NET Excel Library and C#

Adding a watermark to an Excel document using Syncfusion .NET Excel Library and C#

References

For more details, refer to the adding a watermark to Excel using C# GitHub demo and documentation.

Conclusion

Thanks for reading! In this blog, we explored how to add a watermark to an Excel document using C# and Syncfusion .NET Excel Library** (XlsIO)**. The Excel Library also allows you to export Excel data to images, data tables, CSV, TSV, HTML, collections of objects, ODS, JSON, and other file formats. Also, for more details, refer to our .NET Excel library documentation and demos.

Feel free to try this versatile .NET Excel Library and share your feedback in the comments section!

For our existing customers, the new version of Essential Studio is available on our License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!

Related blogs

documentprocessing Article's
21 articles in total
Favicon
Introducing the Syncfusion® Document Viewer Extension for Visual Studio Code
Favicon
What’s New in Document Processing Libraries: 2024 Volume 4
Favicon
Easily Convert Excel to HTML in 3 Steps With C#
Favicon
How to Effectively Use Formulas in Excel Using C#
Favicon
Easily Create Dynamic Charts in Excel Using C#
Favicon
6 Effective Ways to Merge PDF Files Using C#
Favicon
Top Intelligent Document Processing Software for 2024
Favicon
What’s New in Document Processing Libraries: 2024 Volume 3
Favicon
AI-driven OCR Revolutionizes Intelligent Layout Analysis with 24+ Labels
Favicon
Syncfusion Essential Studio 2024 Volume 3 Is Here!
Favicon
3 Easy Steps to Add Watermarks to Your Excel Document Using C#
Favicon
4 Simple Ways to Split Word Documents Using C#
Favicon
How to Integrate Intelligent Document Processing into Your Business Workflow?
Favicon
What’s New in 2024 Volume 2: Document Processing Libraries
Favicon
Syncfusion Essential Studio 2024 Volume 2 Is Here!
Favicon
How BoldSign Improved HR Operations at Syncfusion
Favicon
Easily Create an Excel Pivot Table in Just 3 Steps Using C#
Favicon
Create a Web API Application with our Office File API (Powered by the platform-agnostic DevExpress.Drawing Graphics Engine)
Favicon
From pixels to information with Document AI
Favicon
Automate identity document processing with Document AI
Favicon
Scalable Processing of Swiss PDF Documents using 2D Barcodes on AWS

Featured ones: