2008-10-14 85 views

回答

8

Microsoft提供了一個非常有用的小程序集DSOFile。通過在項目中引用它,您可以修改Office文檔屬性。它不一定會讓你打開實際的Office文件的屬性對話框,但你當然可以模擬它。

據微軟稱:

的Dsofile.dll文件允許您在做 沒有安裝Office

更多細節和下載鏈接可以在這裏找到你編輯 Office文檔屬性http://support.microsoft.com/kb/224351

這是一段代碼,我很久以前就使用了一些(很老的)VB代碼。對不起,我還沒有轉換到C#,並知道它是一個類的一部分,所以有實例變量的引用。儘管如此,它應該很容易理解和隱藏自己的需求:

Private Sub ProcessOfficeDocument(ByVal fileName As String) 
    Dim docDSO As New DSOFile.OleDocumentPropertiesClass 
    Dim docTitle, docModified, docAuthor, docKeywords As String 
    Try 
     docDSO.Open(fileName, True) 
     Dim docSummary As DSOFile.SummaryProperties = docDSO.SummaryProperties 
     docTitle = docSummary.Title 
     docAuthor = docSummary.Author 
     docKeywords = docSummary.Keywords 
     docModified = CStr(docSummary.DateLastSaved) 

     If (Not String.IsNullOrEmpty(docTitle)) Then 
      _Title = docTitle 
     End If 

     If (Not String.IsNullOrEmpty(docAuthor)) Then 
      _Author = docAuthor 
     End If 

     If (Not String.IsNullOrEmpty(docModified)) Then 
      _DateModified = DateTime.Parse(docModified) 
     End If 

    Catch ex As Exception 
     'Do whatever you need to do here...' 
    Finally 
     If (Not docDSO Is Nothing) Then 
      docDSO.Close() 
     End If 
    End Try 
End Sub 
+0

我會+5這個,如果我可以..很好的答案。 – torial 2008-12-08 19:24:00

5

我能想到的2種方法來做到這一點:

我會選擇第二個選項去,如果可以的話,因爲要在系統上安裝的方式,你不必依賴字。

相關問題