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:
Full Code:
[C#]
using Spire.Xls; using System; namespace AddCustomProperties { class Program { static void Main(string[] args) { { 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]
Imports Spire.Xls Namespace AddCustomProperties Class Program Private Shared Sub Main(args As String()) If True Then Dim wb As 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) End If End Sub End Class End Namespace