C# 在C中列出word文档的属性#

C# 在C中列出word文档的属性#,c#,reflection,properties,ms-word,C#,Reflection,Properties,Ms Word,我想要一些帮助来检索word文档的属性。我已经拿到了书名、主题和作者。但我似乎无法获取“上次保存的日期”属性,也不知道如何获取属性名称列表 我的代码如下所示: using System; using System.Collections.Generic; using System.Text; using Microsoft.Office.Interop; using System.Reflection; using System.IO; namespace MetaDataSorter {

我想要一些帮助来检索word文档的属性。我已经拿到了书名、主题和作者。但我似乎无法获取“上次保存的日期”属性,也不知道如何获取属性名称列表

我的代码如下所示:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop;
using System.Reflection;
using System.IO;


namespace MetaDataSorter
{
    class Program
    {

    static void Main(string[] args)
    {
        String dirName = @"H:\projekt\test raw files";

        String fileNameString = @"H:\projekt\raw files\vgahm\1 NTFS\Raw Files\Microsoft Word Document\1-300\FILE006.DOC";
        object fileName = (object)fileNameString;

        object missing = System.Reflection.Missing.Value;

        Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();


        Microsoft.Office.Interop.Word.Document aDoc = null;

        if (File.Exists((string)fileName))
        {
            DateTime toDay = DateTime.Now;

            object readOnly = false;
            object isVisible = false;

            wordApp.Visible = false;

            aDoc = wordApp.Documents.Open(ref fileName, ref missing, 
                ref readOnly, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing);

            aDoc.Activate();

            //object property = getWordDocumentPropertyValue(aDoc, "Title");

            System.Console.WriteLine("property: " + getWordDocumentPropertyValue(aDoc, "Title"));
            System.Console.WriteLine("property: " + getWordDocumentPropertyValue(aDoc, "Subject"));
            System.Console.WriteLine("property: " + getWordDocumentPropertyValue(aDoc, "Author"));
            //System.Console.WriteLine("property: " + getWordDocumentPropertyValue(aDoc, "Date Last Saved"));

            aDoc.Close();
        }

    }

    private static String getWordDocumentPropertyValue(Microsoft.Office.Interop.Word.Document document, string propertyName)
    {
        object builtInProperties = document.BuiltInDocumentProperties;

        Type builtInPropertiesType = builtInProperties.GetType();

        object property = builtInPropertiesType.InvokeMember("Item", BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName });

        Type propertyType = property.GetType();
        object propertyValue = propertyType.InvokeMember("Value", BindingFlags.GetProperty, null, property, new object[] { });
        return propertyValue.ToString();
    }

}
}

如何获取属性值列表?

您可以从查看类BuildinDocumentProperties开始,或者使用此链接作为起点

请记住,有些属性特定于office套件中的某些产品,有些属性是常见的。你要找的那个肯定是个普通的


关于word,请在此处找到列表

您可以从查看类内置文档属性开始,或者使用此链接作为起点

请记住,有些属性特定于office套件中的某些产品,有些属性是常见的。你要找的那个肯定是个普通的


关于word,请在此处找到列表

将VBA模块中的此代码粘贴到word文档中,即可获得属性列表

Sub ListeProprietes()
   Dim proDoc As DocumentProperty

   For Each proDoc In ActiveDocument.BuiltInDocumentProperties

        MsgBox (proDoc.Name)

   Next

End Sub

将VBA模块中的此代码粘贴到Word文档中,即可获得属性列表

Sub ListeProprietes()
   Dim proDoc As DocumentProperty

   For Each proDoc In ActiveDocument.BuiltInDocumentProperties

        MsgBox (proDoc.Name)

   Next

End Sub

谢谢但那没用。我在添加使用办公用品所需的参考资料时遇到了问题。然而,我解决了这个问题,无意中发现了我可以使用“最后一次节省时间”,这就是酒店的名称:)谢谢!但那没用。我在添加使用办公用品所需的参考资料时遇到了问题。然而,我解决了这个问题,无意中发现我可以使用“最后一次节省时间”,这就是酒店名称:)