Excel File Properties

The following example shows how to read and write Excel file's Document Properties like Title, Author, Comments, etc.

Excel file properties set with GemBox.Spreadsheet
Screenshot of Excel file properties set with GemBox.Spreadsheet
Upload your file (Drag file here)
using GemBox.Spreadsheet;

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

        var workbook = ExcelFile.Load("%InputFileName%");

        // Add Sheet.
        var worksheet = workbook.Worksheets.ActiveWorksheet = workbook.Worksheets.InsertEmpty(0, "Document Properties");

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

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

        foreach (var keyValue in workbook.DocumentProperties.BuiltIn)
        {
            worksheet.Cells[rowIndex, 0].Value = keyValue.Key.ToString();
            worksheet.Cells[rowIndex++, 1].Value = keyValue.Value;
        }

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

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

        foreach (var keyValue in workbook.DocumentProperties.Custom)
        {
            worksheet.Cells[rowIndex, 0].Value = keyValue.Key;
            worksheet.Cells[rowIndex++, 1].Value = keyValue.Value.ToString();
        }

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

        worksheet.Columns[0].SetWidth(192, LengthUnit.Pixel);
        worksheet.Columns[1].SetWidth(217, LengthUnit.Pixel);

        workbook.Save("Document Properties.%OutputFileType%");
    }
}
Imports GemBox.Spreadsheet

Module Program

    Sub Main()

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

        Dim workbook = ExcelFile.Load("%InputFileName%")

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

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

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

        For Each keyValue In workbook.DocumentProperties.BuiltIn

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

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

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

        For Each keyValue In workbook.DocumentProperties.Custom

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

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

        worksheet.Columns(0).SetWidth(192, LengthUnit.Pixel)
        worksheet.Columns(1).SetWidth(217, LengthUnit.Pixel)

        workbook.Save("Document Properties.%OutputFileType%")
    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Spreadsheet yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.