如何检查是否检出Excel文件

我试图检出并编辑一个Excel文件。 有可能在代码运行的时候,文件已经被同一台计算机上的同一个用户检出了。 在这种情况下CanCheckOut()返回false,下面的代码不起作用。

 // xlsAsp is an instance of Microsoft.Office.Interop.Excel.Application if (!xlsApp.Workbooks.CanCheckOut(fileName)) { Console.WriteLine("File {0} cannot be checked out", fileName); return; } Console.WriteLine("Attempting to check out {0}", fileName); currentBook = xlsApp.Workbooks.Open(fileName); xlsApp.Workbooks.CheckOut(fileName); // Do something currentBook.CheckIn(SaveChanges: true); 

我想更改代码来处理文件签出时的情况。

是否有可能以某种方式validation文件是否已经签出,以避免第二次检查?