2011-11-08 3 views
2

단어 문서의 속성을 검색하는 데 도움이되고 싶습니다. 나는 제목, 주제 및 저자를 얻는 한까지 얻었습니다. 하지만 "마지막으로 저장 한 날짜"속성을 가져올 수 없으며 속성 이름 목록을 가져 오는 방법을 알지 못합니다.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 나는 "Last 저장 시간 ", 그것은 속성 이름 :) – user1028037

-1

Word 문서에 VBA 모듈에서이 코드를 붙여 당신은 속성의 목록을 목록을 찾을 수 있습니다.

Sub ListeProprietes() 
    Dim proDoc As DocumentProperty 

    For Each proDoc In ActiveDocument.BuiltInDocumentProperties 

     MsgBox (proDoc.Name) 

    Next 

End Sub 
관련 문제