Excel File Properties

Following example demonstrates how to read and write Excel file's Document Properties like Title, Author, Comments, etc.

Document Properties Screenshot
Upload your file (Drag file here)
using System;
using System.Collections.Generic;
using GemBox.Spreadsheet;

class Program
{
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        ExcelFile ef = ExcelFile.Load("%InputFileName%");

        // Add Sheet
        ExcelWorksheet ws = ef.Worksheets.ActiveWorksheet = ef.Worksheets.InsertEmpty(0, "Document Properties");

        int rowIndex = 0;
        // Read Built-in Document Properties 
        ws.Cells[rowIndex++, 0].Value = "Built-in document properties";

        ws.Cells[rowIndex, 0].Value = "Property";
        ws.Cells[rowIndex++, 1].Value = "Value";

        foreach (KeyValuePair<BuiltInDocumentProperties, string> keyValue in ef.DocumentProperties.BuiltIn)
        {
            ws.Cells[rowIndex, 0].Value = keyValue.Key.ToString();
            ws.Cells[rowIndex++, 1].Value = keyValue.Value;
        }

        // Read Custom Document Properties
        ws.Cells[++rowIndex, 0].Value = "Custom Document Properties";

        ws.Cells[++rowIndex, 0].Value = "Property";
        ws.Cells[rowIndex++, 1].Value = "Value";

        foreach (KeyValuePair<string, object> keyValue in ef.DocumentProperties.Custom)
        {
            ws.Cells[rowIndex, 0].Value = keyValue.Key;
            ws.Cells[rowIndex++, 1].Value = keyValue.Value.ToString();
        }

        // Write/Modify Document Properties
        ef.DocumentProperties.BuiltIn[BuiltInDocumentProperties.Author] = "John Doe";
        ef.DocumentProperties.BuiltIn[BuiltInDocumentProperties.Title] = "Generated title";

        ws.Columns[0].AutoFit();
        ws.Columns[1].AutoFit();

        ef.Save("Document Properties.%OutputFileType%");
    }
}
Imports System
Imports System.Collections.Generic
Imports GemBox.Spreadsheet

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        Dim ef As ExcelFile = ExcelFile.Load("%InputFileName%")

        ' Add Sheet
        Dim ws As ExcelWorksheet = ef.Worksheets.InsertEmpty(0, "Document Properties")
        ef.Worksheets.ActiveWorksheet = ws

        Dim rowIndex As Integer = 0
        ' Read Built-in Document Properties 
        ws.Cells(rowIndex, 0).Value = "Built-in document properties"
        rowIndex = rowIndex + 1

        ws.Cells(rowIndex, 0).Value = "Property"
        ws.Cells(rowIndex, 1).Value = "Value"
        rowIndex = rowIndex + 1

        For Each keyValue As KeyValuePair(Of BuiltInDocumentProperties, String) In ef.DocumentProperties.BuiltIn

            ws.Cells(rowIndex, 0).Value = keyValue.Key.ToString()
            ws.Cells(rowIndex, 1).Value = keyValue.Value
            rowIndex = rowIndex + 1

        Next

        ' Read Custom Document Properties
        rowIndex = rowIndex + 1
        ws.Cells(rowIndex, 0).Value = "Custom Document Properties"

        rowIndex = rowIndex + 1
        ws.Cells(rowIndex, 0).Value = "Property"
        ws.Cells(rowIndex, 1).Value = "Value"
        rowIndex = rowIndex + 1

        For Each keyValue As KeyValuePair(Of String, Object) In ef.DocumentProperties.Custom

            ws.Cells(rowIndex, 0).Value = keyValue.Key
            ws.Cells(rowIndex, 1).Value = keyValue.Value.ToString()
            rowIndex = rowIndex + 1

        Next

        ' Write/Modify Document Properties
        ef.DocumentProperties.BuiltIn(BuiltInDocumentProperties.Author) = "John Doe"
        ef.DocumentProperties.BuiltIn(BuiltInDocumentProperties.Title) = "Generated title"

        ws.Columns(0).AutoFit()
        ws.Columns(1).AutoFit()

        ef.Save("Document Properties.%OutputFileType%")

    End Sub

End Module

Check next example or download examples from GitHub.