How can I add to the Author property of an Excel document automatically? I want to use c# 4 for this.
Asked
Active
Viewed 1,832 times
2 Answers
0
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

fluf
- 1,261
- 2
- 22
- 36
0
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";

Chris Spicer
- 2,144
- 1
- 13
- 22