GemBox.Spreadsheet is a .NET component that enables you to read, write, edit, convert, and print spreadsheet files from your .NET applications using one simple API.

Excel File Properties

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

Screenshot
Document Properties Screenshot

See the full code below, use Run Example to execute.

Upload your file(Drag files here)

Download a sample file

using System;
using System.Collections.Generic;
using System.Text;
using GemBox.Spreadsheet;
using GemBox.Spreadsheet.ConditionalFormatting;
using GemBox.Spreadsheet.PivotTables;

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

        ExcelFile ef = ExcelFile.Load("TemplateUse.xlsx");

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

        int rowIndex = 0;
        // Read Built-in Document Properies 
        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/Modifiy Document Properties
        ef.DocumentProperties.BuiltIn[BuiltInDocumentProperties.Author] = "John Doe";
        ef.DocumentProperties.BuiltIn[BuiltInDocumentProperties.Title] = "Genrated title";

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

        ef.Save("Document Properties.xlsx");
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports GemBox.Spreadsheet
Imports GemBox.Spreadsheet.ConditionalFormatting
Imports GemBox.Spreadsheet.PivotTables

Module Samples

    Sub Main()

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

        Dim ef As ExcelFile = ExcelFile.Load("TemplateUse.xlsx")

        ' 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 Properies 
        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/Modifiy Document Properties
        ef.DocumentProperties.BuiltIn(BuiltInDocumentProperties.Author) = "John Doe"
        ef.DocumentProperties.BuiltIn(BuiltInDocumentProperties.Title) = "Genrated title"

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

        ef.Save("Document Properties.xlsx")

    End Sub

End Module

Check next sample.