开发者

Manipulate Excel files

开发者 https://www.devze.com 2023-02-05 18:56 出处:网络
How can I add to the Author property of an Excel document开发者_C百科 automatically? I want to use c# 4 for this.Document Properties This link explains how to read the document properties and gives a

How can I add to the Author property of an Excel document开发者_C百科 automatically? I want to use c# 4 for this.


Document Properties This link explains how to read the document properties and gives a list of properties which you can access.

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;
    }
}

}

Here's a list of imports required :

using Microsoft.Office.Interop.Excel; using Microsoft.Office.Core; // (Com Object, Office 12 object library)`

Microsoft.Office.Core.DocumentProperties a = (Microsoft.Office.Core.DocumentProperties)workbook.BuiltinDocumentProperties; a[2].Value = "new Author";

Hope that helps


As you specified C# 4, you can use the following:

Workbook wbk = app.Workbooks.Add();

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

property.Value = "J K Rowling";    
0

精彩评论

暂无评论...
验证码 换一张
取 消