2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
Syncfusion Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. Also, converts Excel documents to PDF files. Using this library, you can insert watermark in Excel worksheet. Steps to insert watermark in Excel document, programmatically:
Create a new C# console application project
Install NuGet package to the project
C# //Insert image watermark in the worksheet Stream imageStream = assembly.GetManifestResourceStream("Watermark.image.png"); worksheet.PageSetup.BackgoundImage = new Bitmap(imageStream);
VB.NET 'Insert image watermark in the worksheet Dim imageStream As Stream = assembly.GetManifestResourceStream("Watermark.image.png") worksheet.PageSetup.BackgoundImage = New Bitmap(imageStream)
Note: To insert a text watermark, you need to take image of text and insert it in the background using the same BackgroundImage property.
C# using Syncfusion.XlsIO; using System.Drawing; using System.IO; using System.Reflection;
VB.NET Imports Syncfusion.XlsIO Imports System.Drawing Imports System.IO Imports System.Reflection
C# using (ExcelEngine excelEngine = new ExcelEngine()) { //Initailize the excel application object IApplication application = excelEngine.Excel; //Load an existing Excel file into IWorkbook Assembly assembly = typeof(Program).GetTypeInfo().Assembly; Stream fileStream = assembly.GetManifestResourceStream("Watermark.Sample.xlsx"); IWorkbook workbook = application.Workbooks.Open(fileStream, ExcelOpenType.Automatic); //Get the first worksheet in workbook into IWorksheet IWorksheet worksheet = workbook.Worksheets[0]; //Insert image watermark in the worksheet Stream imageStream = assembly.GetManifestResourceStream("Watermark.image.png"); worksheet.PageSetup.BackgoundImage = new Bitmap(imageStream); //Save the Excel workbook workbook.SaveAs("Output.xlsx"); }
VB.NET Using excelEngine As ExcelEngine = New ExcelEngine() 'Initailize the excel application object Dim application As IApplication = excelEngine.Excel 'Load an existing Excel file into IWorkbook Dim assembly As Assembly = GetType(Module1).GetTypeInfo.Assembly Dim fileStream As Stream = assembly.GetManifestResourceStream("Watermark.Sample.xlsx") Dim workbook As IWorkbook = application.Workbooks.Open(fileStream, ExcelOpenType.Automatic) 'Get the first worksheet in workbook into IWorksheet Dim worksheet As IWorksheet = workbook.Worksheets(0) 'Insert image watermark in the worksheet Dim imageStream As Stream = assembly.GetManifestResourceStream("Watermark.image.png") worksheet.PageSetup.BackgoundImage = New Bitmap(imageStream) 'Save the Excel workbook workbook.SaveAs("Output.xlsx") End Using
A complete working sample of how to insert watermark in Excel document can be downloaded from Watermark.zip. By executing the program, you will get the output Excel document as follows. Output Excel document Take a moment to peruse the documentation, where you will find other options like move or copy a worksheet, freeze, unfreeze and split panes, show or hide worksheet and worksheet tabs, page setup settings and more with code examples. Click here to explore the rich set of Syncfusion Excel (XlsIO) library features. Note: Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer the link to learn about generating and registering Syncfusion license key in your application to use the components without trial message.
|
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.