C# 如何创建和修改office文件的自定义文档属性
我在看这篇文章,但Office.DocumentProperties抛出了一个错误,即Office没有定义DocumentPropertiesC# 如何创建和修改office文件的自定义文档属性,c#,ms-word,vsto,ms-office,office-addins,C#,Ms Word,Vsto,Ms Office,Office Addins,我在看这篇文章,但Office.DocumentProperties抛出了一个错误,即Office没有定义DocumentProperties private void Ribbon1_Load(object sender, RibbonUIEventArgs e) { Microsoft.Office.Core.DocumentProperties properties; var activeDocument = Globals.ThisDocumen
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
Microsoft.Office.Core.DocumentProperties properties;
var activeDocument = Globals.ThisDocument.Application.ActiveDocument;
properties = (Microsoft.Office.Core.DocumentProperties)activeDocument.CustomDocumentProperties;
MessageBox.Show(JsonConvert.SerializeObject(properties));
}
本文介绍如何读取和写入文档属性。下面的代码在我的电脑上很有魅力:
Word.Document doc = WordApp.ActiveDocument as Word.Document;
Office.DocumentProperties properties = doc.CustomDocumentProperties as Office.DocumentProperties;
for (int i = 0; i < properties.Count; i++)
{
Office.DocumentProperty property = properties[i];
if(property!=null)
{
System.Windows.Forms.MessageBox.Show(property.Name);
Marshal.ReleaseComObject(property);
}
}
if (properties != null) Marshal.ReleaseComObject(properties);
if (doc != null) Marshal.ReleaseComObject(doc);
请您使用问题下方的链接,将您尝试过的代码作为用户共享,好吗?您可能还需要阅读网站指南,以便在中提出有效的问题。用你正在使用的编程语言标记这个问题也是一个好主意。你的代码对我很有用。你能不能也包括引起错误的那一行和错误信息?请检查项目引用,以确保有对
Office
PIA的引用。我在Office类下找不到DocumentProperties。您使用哪一个图书馆参考资料?
dynamic properties = doc.CustomDocumentProperties;