0

可以计算从word文档“打开”(通常是双击文档进行的操作)到在Word中有效查看文档所经过的时间吗?

我认为我的时间跨度的开始可能是应用程序的过程。开始。但是我怎么知道文档何时在 Microsoft Word 中有效打开?

4

1 回答 1

1

互操作是同步的,所以你应该能够做到这一点:

string path = "";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
var excel = new Microsoft.Office.Interop.Excel.Application();
excel.Workbooks.Open(path, Type.Missing, false, Type.Missing, Type.Missing,
                Type.Missing, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing, Type.Missing);
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;

// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
            ts.Hours, ts.Minutes, ts.Seconds,
            ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);
Console.ReadKey();
于 2013-09-05T14:26:18.980 回答