How to Add Custom Properties to Excel Document in C#, VB.NET

Custom properties, as a supplement to built-in properties, provide additional information to a document that is deemed useful by author. This article introduces how to add custom properties to an Excel document using Spire.XLS in C#, VB.NET.

Step 1: Create an instance of Workbook.

Workbook wb = new Workbook();

Step 2: Add a custom property which can mark the document as final.

wb.CustomDocumentProperties.Add("_MarkAsFinal", true);

Step 3: Add more custom properties to the document.

wb.CustomDocumentProperties.Add("The Editor", "E-iceblue");
wb.CustomDocumentProperties.Add("Phone number", 81705109);
wb.CustomDocumentProperties.Add("Revision number", 7.12);
wb.CustomDocumentProperties.Add("Revision date", DateTime.Now);

Step 4: Save the file.

wb.SaveToFile("output.xlsx", FileFormat.Version2013);

Output:

How to Add Custom Properties to Excel Document in C#, VB.NET

Full Code:

[C#]
Workbook wb = new Workbook();

wb.CustomDocumentProperties.Add("_MarkAsFinal", true);
wb.CustomDocumentProperties.Add("The Editor", "E-iceblue");
wb.CustomDocumentProperties.Add("Phone number", 81705109);
wb.CustomDocumentProperties.Add("Revision number", 7.12);
wb.CustomDocumentProperties.Add("Revision date", DateTime.Now);

wb.SaveToFile("output.xlsx", FileFormat.Version2013);
[VB.NET]
Dim wb As Workbook =  New Workbook() 
 
wb.CustomDocumentProperties.Add("_MarkAsFinal", True)
wb.CustomDocumentProperties.Add("The Editor", "E-iceblue")
wb.CustomDocumentProperties.Add("Phone number", 81705109)
wb.CustomDocumentProperties.Add("Revision number", 7.12)
wb.CustomDocumentProperties.Add("Revision date", DateTime.Now)
 
wb.SaveToFile("output.xlsx", FileFormat.Version2013)