玩这个周围公平一点,这是我的最终代码的情况下,之后,它可以帮助别人,我发现这种格式更容易理解和使用工作。这一切都被基督教基础上,引用的文章:
using Office = Microsoft.Office.Core;
using Word = Microsoft.Office.Interop.Word;
using System.Reflection;
Office.DocumentProperties properties = (Office.DocumentProperties)Globals.ThisDocument.CustomDocumentProperties;
//Check if the property exists already
if (properties.Cast<Office.DocumentProperty>().Where(c => c.Name == "nameofproperty").Count() == 0)
{
//Then add the property and value
properties.Add("nameofproperty", false, Office.MsoDocProperties.msoPropertyTypeString, "yourvalue");
}
else
{
//else just update the value
properties["nameofproperty"].Value = "yourvalue";
}
在检索它作为使用相同的三条线在顶部获得对象的属性,可能使用该代码的if语句容易值方面检查它是否存在,并检索它使用properties["nameofproperty"].Value
这看起来很完美谢谢你!将有一个去 – ebooyens
玩得开心:)请测试自定义文档属性是否会被覆盖。在Excel中,他们不是,但你永远不知道;) –