处理Excel文件

时间:2011-01-18 05:40:44

标签: c# .net excel

如何自动添加Excel文档的Author属性?我想用c#4来做这件事。

2 个答案:

答案 0 :(得分:0)

文档属性此链接说明如何阅读文档属性并提供可以访问的属性列表。

private void DisplayBuiltinDocumentProperties()

{     Office.DocumentProperties documentProperties1 =         (Office.DocumentProperties)this.BuiltinDocumentProperties;

if (documentProperties1 != null)
{
    for (int i = 1; i <= documentProperties1.Count; i++)
    {
        Office.DocumentProperty dp = documentProperties1[i];
        Globals.Sheet1.Range["A" + i.ToString(), missing].Value2 =
            dp.Name;
    }
}

}

以下是所需的导入列表:

使用Microsoft.Office.Interop.Excel; 使用Microsoft.Office.Core; //(Com Object,Office 12对象库)`

Microsoft.Office.Core.DocumentProperties a =(Microsoft.Office.Core.DocumentProperties)workbook.BuiltinDocumentProperties;             a [2] .Value =“新作者”;

希望有所帮助

答案 1 :(得分:0)

在指定C#4时,您可以使用以下内容:

Workbook wbk = app.Workbooks.Add();

dynamic properties = wbk.BuiltinDocumentProperties;
dynamic property = properties.Item("Author");

property.Value = "J K Rowling";    
相关问题