How to Edit Workbook Metadata in C#

In this video tutorial, coders are guided through the process of editing workbook metadata using IronXL in C#. The tutorial starts with setting up a C# project in Visual Studio and ensuring IronXL is installed via the NuGet Package Manager. By navigating to the Program.cs file, users learn to integrate IronXL into their project by adding the using IronXL; directive at the top.

The tutorial then demonstrates loading an Excel file named sample.xlsx using the IronXL Workbook class. Users are shown how to add metadata such as author, title, comments, and keywords to the Excel file, broadening its informational capacity. Additionally, the tutorial explains how to retrieve and set the file creation and last printed dates. After making these changes, users save their work to a new file named edited_metadata.xlsx. Upon execution, the program applies the changes successfully, allowing users to compare the original and edited files side by side.

The video concludes by highlighting IronXL's capabilities and encouraging viewers to explore further functionalities. Viewers are encouraged to subscribe for more tutorials and check out the IronXL software through the provided link.

Below is the corrected and enhanced C# code, properly formatted and commented:

// Ensure you have installed IronXL through the NuGet Package Manager before running this code.

using IronXL; // Import the IronXL namespace

class Program
{
    static void Main(string[] args)
    {
        // Load the Excel file named 'sample.xlsx' into a workbook
        var workbook = Workbook.Load("sample.xlsx");

        // Assign metadata properties to the workbook
        // Setting the author of the workbook
        workbook.Metadata.Author = "Jane Doe";

        // Setting the title of the workbook
        workbook.Metadata.Title = "Quarterly Report";

        // Setting comments or description of the workbook
        workbook.Metadata.Comments = "This is an edited version of the quarterly report.";

        // Adding keywords for easier searchability
        workbook.Metadata.Keywords = "Q1, Report, Finance";

        // Set the creation date of the workbook metadata
        workbook.Metadata.Created = DateTime.Now;

        // Optionally set when the workbook was last printed
        // Comment this out if not applicable
        // workbook.Metadata.LastPrinted = DateTime.Now;

        // Save the workbook with the updated metadata to a new file
        workbook.SaveAs("edited_metadata.xlsx");

        // Output message signalling completion
        Console.WriteLine("The metadata has been successfully updated and saved.");
    }
}
// Ensure you have installed IronXL through the NuGet Package Manager before running this code.

using IronXL; // Import the IronXL namespace

class Program
{
    static void Main(string[] args)
    {
        // Load the Excel file named 'sample.xlsx' into a workbook
        var workbook = Workbook.Load("sample.xlsx");

        // Assign metadata properties to the workbook
        // Setting the author of the workbook
        workbook.Metadata.Author = "Jane Doe";

        // Setting the title of the workbook
        workbook.Metadata.Title = "Quarterly Report";

        // Setting comments or description of the workbook
        workbook.Metadata.Comments = "This is an edited version of the quarterly report.";

        // Adding keywords for easier searchability
        workbook.Metadata.Keywords = "Q1, Report, Finance";

        // Set the creation date of the workbook metadata
        workbook.Metadata.Created = DateTime.Now;

        // Optionally set when the workbook was last printed
        // Comment this out if not applicable
        // workbook.Metadata.LastPrinted = DateTime.Now;

        // Save the workbook with the updated metadata to a new file
        workbook.SaveAs("edited_metadata.xlsx");

        // Output message signalling completion
        Console.WriteLine("The metadata has been successfully updated and saved.");
    }
}
' Ensure you have installed IronXL through the NuGet Package Manager before running this code.

Imports IronXL ' Import the IronXL namespace

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		' Load the Excel file named 'sample.xlsx' into a workbook
		Dim workbook = Workbook.Load("sample.xlsx")

		' Assign metadata properties to the workbook
		' Setting the author of the workbook
		workbook.Metadata.Author = "Jane Doe"

		' Setting the title of the workbook
		workbook.Metadata.Title = "Quarterly Report"

		' Setting comments or description of the workbook
		workbook.Metadata.Comments = "This is an edited version of the quarterly report."

		' Adding keywords for easier searchability
		workbook.Metadata.Keywords = "Q1, Report, Finance"

		' Set the creation date of the workbook metadata
		workbook.Metadata.Created = DateTime.Now

		' Optionally set when the workbook was last printed
		' Comment this out if not applicable
		' workbook.Metadata.LastPrinted = DateTime.Now;

		' Save the workbook with the updated metadata to a new file
		workbook.SaveAs("edited_metadata.xlsx")

		' Output message signalling completion
		Console.WriteLine("The metadata has been successfully updated and saved.")
	End Sub
End Class
$vbLabelText   $csharpLabel

Further Reading: How to Edit Workbook Metadata

Regan Pun
Software Engineer
Regan graduated from the University of Reading, with a BA in Electronic Engineering. Before joining Iron Software, his previous job roles had him laser-focused on single tasks; and what he most enjoys at Iron Software is the spectrum of work he gets to undertake, whether it’s adding value to sales, technical support, product development or marketing. He enjoys understanding the way developers are using the Iron Software library, and using that knowledge to continually improve documentation and develop the products.
< PREVIOUS
How to Group and Ungroup Rows and Columns in Excel
NEXT >
How to Create and Edit Excel Charts in C#