我需要打开一个微软Word2003年文件和改变其文件的性质。如更改该主题的摘要选项。
alt text

有帮助吗?

解决方案

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

其他提示

我能想到的2种方法可以做到这一点:

我会去的第二个选项,如果可以的话,因为这样你不必依赖字正在安装该系统。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top