2011-11-08 2 views
2

単語文書のプロパティを取得するのに役立つことがあります。私はタイトル、主題、作者を手に入れています。しかし、私は "Date Last Saved"プロパティを取得できないようで、プロパティ名のリストを取得する方法はわかりません。C#での単語文書のプロパティのリスト

私のコードは次のようになります。

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(); 
    } 

} 
} 

はどのようにして、プロパティ値の一覧を取得しようとして行くべき?あなたはおそらくクラスは、BuiltInDocumentPropertiesまたは出発点として、このリンクを使用して見を持っていることによって開始することができ

答えて

1

http://support.microsoft.com/default.aspx?scid=kb;en-us;303294いくつかのプロパティは、オフィススイート内の特定の製品に固有のものであり、一部が共通であることを忘れないでください。あなたが探しているのは確かに共通のものです。単語について

、ここhttp://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.wdbuiltinproperty%28v=office.11%29.aspx

+1

ありがとうございました!それはうまくいかなかった。オフィスのものを使うのに必要な参照を追加することに問題がありました。私はそれを解決したが、http://www.codeproject.com/KB/office/MsWordAutoDocProp.aspx?fid=260729&df=90&mpp=25&noise=3&prof=False&sort=Position&view=Quick&fr=18私は "最後のSave Time "、それはプロパティ名でした:) – user1028037

-1

は、Word文書にVBAモジュールでこのコードを貼り付け、あなたがプロパティのリストを取得するリストを見つけます。

Sub ListeProprietes() 
    Dim proDoc As DocumentProperty 

    For Each proDoc In ActiveDocument.BuiltInDocumentProperties 

     MsgBox (proDoc.Name) 

    Next 

End Sub 
関連する問題