News Category

How to Get Excel Properties and Custom Properties in C#

2017-01-10 07:19:56 Written by  support iceblue
Rate this item
(0 votes)

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:

using Spire.Xls;
using Spire.Xls.Collections;
using Spire.Xls.Core;
namespace GetExcelProperties
{
    class Program
    {

        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;
                }


            }

        }
    }
}

Additional Info

  • tutorial_title: Get Excel Properties and Custom Properties
Last modified on Monday, 06 September 2021 02:08