2008-10-14 83 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种方法来做到这一点:

我会选择第二个选项去,如果可以的话,因为要在系统上安装的方式,你不必依赖字。

相关问题