How to Get Excel Properties and Custom Properties in C#

We have already shown you how to set the Excel Properties in C# with the help of Spire.XLS. This article focuses introducing method to get Excel properties and custom properties on the Excel workbook in C#.

Here comes to the steps of how to get the Excel Properties even with custom properties:

Step 1: Initialize an instance of Workbook and load the document from file.

Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

Step 2: Use workbook.DocumentProperties to get the general excel properties.

BuiltInDocumentProperties p = workbook.DocumentProperties;

How to Get Excel Properties and Custom Properties in C#

Step 3: Use CustomDocumentProperties property for workbook object to get the custom properties.

ICustomDocumentProperties properties = workbook.CustomDocumentProperties;

for (int i = 0; i < properties.Count; i++)
{
    string name = properties[i].Name;
    string value = properties[i].Text;

 }

How to Get Excel Properties and Custom Properties in C#

Full codes:

static void Main(string[] args)
 
{

     Workbook workbook = new Workbook();
     workbook.LoadFromFile("Sample.xlsx");

   
     BuiltInDocumentProperties p = workbook.DocumentProperties;               

     ICustomDocumentProperties properties = workbook.CustomDocumentProperties;
   
     for (int i = 0; i < properties.Count; i++)
     {
         string name = properties[i].Name;
         string value = properties[i].Text;

      }             
                      
 }