2015-02-24 103 views
0

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

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

+0

您可能感兴趣于来自Microsoft.Office.Interop.Word程序集的“Versions”(https://msdn.microsoft.com/zh-cn/library/microsoft.office.interop.word.versions%28v=office 0.11%29.aspx) – 2015-02-24 15:26:13

回答

1

我会去了解一下该位信息的:

Microsoft Office Library

它的信息,从文件获取版本好位。

你需要做的第一件事情就是添加一个参考:

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]应根据我在文档(未测试)中阅读的内容为您提供最新版本。

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

相关问题