Articles in this section
Category / Section

How to Add Custom Properties to WinForms Excel Document?

2 mins read

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 in WinForms Excel.

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.


Conclusion

I hope you enjoyed learning about how to add custom properties to WinForms Excel document.

You can refer to our WinForms Excel featuretour page to know about its other groundbreaking feature representations and documentation, to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please  to leave a comment
Access denied
Access denied