打开Microsoft Word文档的已用时间

时间:2013-09-05 12:47:51

标签: c# ms-word add-in office-interop

可以计算单词文档“打开”(通常双击文档的操作)到Word中文档的有效视图所用的时间吗?

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

1 个答案:

答案 0 :(得分:1)

Interop是同步的,所以你应该能够这样做:

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();