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
Run Code Online (Sandbox Code Playgroud)
我可以想到两种方法:
如果可以,我会选择第二个选项,因为这样您就不必依赖于系统上安装的Word.