0

在office 2003中,我们可以将不同版本的word文档保存在同一个.doc文件中。但是这个版本功能从 2007 年开始被删除。

是否有任何选项可以检测 .doc 文件是否有任何版本,并通过我们在 c# 中的代码将版本提取到不同的文件中。

4

1 回答 1

1

我会调查一下这些信息:

微软办公库

它有很多关于从文档中获取版本的信息。

您需要做的第一件事是添加对以下内容的引用:

Microsoft.Office.Interop.Word;

然后从要从中提取版本的文件中实例化一个文档:

    Application application = new Application();
    Document document = new Document();

打开文档:

    this.application.Documents.Open(@"C:\Users\...\nameOfDoc.doc", ReadOnly: true);
    document = this.application.Documents["nameOfDoc.doc"];

提取您的版本:

    String documentVersion;
    if (document.Versions.Count > 0)
    {
            documentVersion = document.Versions[document.Versions.Count - 1].ToString();
    }
    else
    {
            documentVersion = "No Versioning";
    }

不是必需的ReadOnly: true,可以根据您想要执行的操作设置为 false。我通常不喜欢拥有不必要的权力。

此外,[document.Versions.Count - 1]应该根据我在文档中阅读的内容(未经测试)为您提供最新版本。

我希望这可以帮助你!如果没有,它应该让你走上正轨。

于 2015-02-24T16:09:40.363 回答