问题描述
使用.NET 4,如何添加自定义属性的文件?
Using .NET 4, how do I add custom properties to a document?
我假设它是这样的:
WordApp // an instance of Microsoft.Office.Interop.Word.Application
.ActiveDocument
.CustomDocumentProperties
.Add...?
我似乎无法找到文档这适用于.NET4 /互操作性展示V14。
I cannot seem to find documentation for this that applies to .NET4/interops v14.
推荐答案
我花了很多的猜测(!远超过12分钟的价值,我很不好意思地说)摸不着头脑:
It took a lot of guessing (much more than 12 minutes worth, I'm embarrassed to say!) to figure this out:
WordApp // an instance of Microsoft.Office.Interop.Word.Application
.ActiveDocument
.CustomDocumentProperties
.Add(Name: "PropertyName",
LinkToContent: false,
Type: 4,
Value: "PropertyValue");
我找不到一个像样的枚举的类型,所以我挖了一个神奇的数字4出了一个论坛帖子的字符串
和它的作品...
I couldn't find a decent enum for the types, so I dug the magic number "4" out of a forum post for string
and it works...
有关休闲的浏览器,这是棘手,因为 CustomDocumentProperties
是动态的,所以我没有得到任何的智能感知。出于某种原因,我无法找到此文档。
For casual browsers, this was tricky because CustomDocumentProperties
is dynamic, so I get no Intellisense. And for some reason, I cannot find docs on this.
这篇关于如何添加自定义属性到一个Word文档使用.NET 4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!