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

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();
            }
        }
    }
}

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!