)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Add custom properties into Excel document

Platform: WinForms |
Control: XlsIO |
Published Date: February 15, 2018 |
Last Revised Date: October 27, 2020

Syncfusion Essential XlsIO is a .NET Excel library used to create, read, and edit Excel documents. Using this library, you can add custom properties in Excel document in C# and VB.NET.

Document properties, also known as metadata, are details about a file that describe or identify it. There are four types of document properties namely,

  1. Standard properties
  2. Automatically updated properties
  3. Custom properties
  4. Document library properties

Custom document properties can be selected from the list of names or can be defined on your own. You can select type of property as date, text, number or yes or no and assign a value. 

Steps to add custom properties in Excel document programmatically:

Step 1: Create a new C# console application project.

Create new empty console application in visual studio

Step 2: Install the Syncfusion.XlsIO.WinForms NuGet package as reference to your .NET Framework application from NuGet.Org.

Add XlsIO reference to the project

Step 3: Include the following namespace in the program.cs file.

C#

using Syncfusion.XlsIO;

 

VB.NET

Imports Syncfusion.XlsIO

 

Step 4: Use the following code snippet to add custom properties in Excel file.

C#

using (ExcelEngine excelEngine = new ExcelEngine())
{
  //Instantiate the excel application object
  IApplication application = excelEngine.Excel;
  
  //The workbook is opened
  IWorkbook workbook;
  
  //Creating a workbook 4 worksheets
  workbook = application.Workbooks.Create(4);
 
  #region CustomProperites
  
  //Add custom properties to workbook
  workbook.CustomDocumentProperties["Department"].Text = "XlsIO";
  workbook.CustomDocumentProperties["Module"].Text = "Shapes";
  workbook.CustomDocumentProperties["Status"].Text = "Completed";
  workbook.CustomDocumentProperties["Worksheets_Count"].Value = workbook.Worksheets.Count;
  #endregion
 
  //Save the workbook with added custom properties and close
  Stream stream = File.Create("Output.xlsx");
  workbook.SaveAs(stream);
}

 

VB.NET

Using excelEngine As ExcelEngine = New ExcelEngine
   
   'Instantiate the excel application object
   Dim application As IApplication = excelEngine.Excel
   
   'The workbook is opened
   Dim workbook As IWorkbook
   
   'Creating a workbook 4 worksheets
   workbook = application.Workbooks.Create(4)
   
   'Add custom properties to workbook
   workbook.CustomDocumentProperties("Department").Text = "XlsIO"
   workbook.CustomDocumentProperties("Module").Text = "Shapes"
   workbook.CustomDocumentProperties("Status").Text = "Completed"
   workbook.CustomDocumentProperties("Worksheets_Count").Value = workbook.Worksheets.Count
 
   'Save the workbook with added custom properties and close
   Dim stream As Stream = File.Create("Outpur.xlsx")
   workbook.SaveAs(stream)
End Using

 

A complete working example to add custom properties into Excel document can be downloaded from Add-Custom-properties-in-Excel-document.zip.

By executing the program, you will get the output as follows.

Add custom document properties in Excel using XlsIO

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 trail message.

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon