如何在C#中编辑工作簿元数据

How to Edit Workbook Metadata

This article was translated from English: Does it need improvement?
Translated
View the article in English

Metadata for an Excel spreadsheet includes information about the title, author, subject, keywords, creation date, modification date, and other relevant details. Metadata provides context and helps in organizing and categorizing spreadsheets. It simplifies file search and management, especially when working with multiple spreadsheet files.

Quickstart: Edit workbook metadata in one easy step

Set, modify, and save properties like Title, Author, or Keywords using IronXL’s Metadata interface. No need for Interop—get started instantly with just a few lines of clean, intuitive C# code.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. Copy and run this code snippet.

    IronXL.WorkBook.Load("input.xlsx").Metadata.Title = "Financial Summary";
    // Then save your update to a new file
    IronXL.WorkBook.Load("input.xlsx").SaveAs("output.xlsx");
  3. Deploy to test on your live environment

    Start using IronXL in your project today with a free trial
    arrow pointer

Edit Workbook Metadata Example

To edit the author name of a spreadsheet file, set the Author property with the desired string of data. For example, workBook.Metadata.Author = "Your Name". The metadata information available in the Metadata property of WorkBook class can be accessed and retrieved.

:path=/static-assets/excel/content-code-examples/how-to/edit-workbook-metadata.cs
using IronXL;
using System;

WorkBook workBook = WorkBook.Load("sample.xlsx");

// Set author
workBook.Metadata.Author = "Your Name";
// Set comments
workBook.Metadata.Comments = "Monthly report";
// Set title
workBook.Metadata.Title = "July";
// Set keywords
workBook.Metadata.Keywords = "Report";

// Read the creation date of the excel file
DateTime? creationDate = workBook.Metadata.Created;

// Read the last printed date of the excel file
DateTime? printDate = workBook.Metadata.LastPrinted;

workBook.SaveAs("editedMetadata.xlsx");
Imports IronXL
Imports System

Private workBook As WorkBook = WorkBook.Load("sample.xlsx")

' Set author
workBook.Metadata.Author = "Your Name"
' Set comments
workBook.Metadata.Comments = "Monthly report"
' Set title
workBook.Metadata.Title = "July"
' Set keywords
workBook.Metadata.Keywords = "Report"

' Read the creation date of the excel file
Dim creationDate? As DateTime = workBook.Metadata.Created

' Read the last printed date of the excel file
Dim printDate? As DateTime = workBook.Metadata.LastPrinted

workBook.SaveAs("editedMetadata.xlsx")
$vbLabelText   $csharpLabel
Metadata

Accessible Metadata Fields

Not all metadata properties can be edited or changed. Some properties can only be retrieved. Below is a list of the available properties:

Set, Modify, and Retrieve

  • Author
  • Comments
  • LastPrinted
  • Keywords and Category
  • Created and ModifiedDate
  • Subject and Title

Retrieve Only

  • ApplicationName
  • CustomProperties
  • Company
  • Manager
  • Template

常见问题解答

如何使用C#编辑Excel工作簿元数据?

您可以使用C#中的IronXL库编辑工作簿元数据。它允许您修改诸如标题、作者、主题和关键词等属性,而无需依赖Office Interop。

编辑Excel工作簿元数据的编程步骤是什么?

要编程编辑Excel工作簿元数据,首先下载IronXL库,然后加载或创建电子表格。使用Metadata属性修改元数据详细信息,最后保存具有更新属性的电子表格。

我可以使用C#更改Excel工作簿的作者吗?

是的,您可以使用IronXL库更改Excel工作簿的作者。通过设置作者属性更新此元数据字段:workBook.Metadata.Author = "Your Name";

使用IronXL可以修改哪些元数据属性?

IronXL允许修改元数据属性,如作者、评论、最后打印时间、关键词、类别、创建和修改日期、主题和标题。

使用IronXL修改元数据属性有任何限制吗?

是的,一些元数据属性如ApplicationName、CustomProperties、Company、Manager和Template只能检索而不能修改。

为什么编辑工作簿元数据很重要?

编辑工作簿元数据对于提供更好的上下文、组织和分类电子表格至关重要,这简化了文件搜索和管理,尤其是在处理多个文件时。

如何在使用C#编辑工作簿元数据后保存工作簿?

在编辑工作簿元数据后,您可以使用IronXL的SaveAs方法保存工作簿。例如:workBook.SaveAs("updatedWorkbook.xlsx");

在哪里可以找到用于编辑工作簿元数据的IronXL库?

IronXL库可以从NuGet软件包库下载:https://nuget.org/packages/IronXL.Excel/

使用IronXL编辑工作簿元数据比Office Interop有什么优势?

使用IronXL编辑工作簿元数据的优势在于不需要Office Interop,使开发人员可以更简单高效地编程管理Excel文件。

Chaknith Bin
软件工程师
Chaknith 在 IronXL 和 IronBarcode 工作。他在 C# 和 .NET 方面有着深厚的专业知识,帮助改进软件并支持客户。他从用户互动中获得的见解有助于更好的产品、文档和整体体验。
准备开始了吗?
Nuget 下载 1,686,155 | 版本: 2025.11 刚刚发布