检测用户何时打开单词文档以及何时键入单词文档(在c#中) [英] detecting when a user opens a word document and when he types in it (in c#)

查看:72
本文介绍了检测用户何时打开单词文档以及何时键入单词文档(在c#中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行以下操作: 每当打开Word文档时,我都需要以某种方式保存它,然后,如果用户开始输入它,我想节省文档编辑的时间. 我只是处于第一阶段,似乎无法管理用户何时打开文档. 我尝试使用Microsoft.Office.Interop.Word,但是,除非用户打开文档,否则我不希望启动Word应用程序.但是,当我要初始化Microsoft.Office.Interop.Word.Application时,这是我认为可能的唯一方法. 有没有一种方法,通过使用Microsoft.Office.Interop.Word API来检测用户打开文件的事件?

i'd like to do the following : whenever a word document is open i need to save it in a way, and then if a user starts typing in it i want to save the time the document is being edited. i'm just on the first phase, and i can't seem to manage detecting when a user opens a document. i tried using Microsoft.Office.Interop.Word, but, in this way i don't want to start word application unless the user opens a document. but, when i want to initialize a Microsoft.Office.Interop.Word.Application, it's the only way i saw possible. is there a way, by using the Microsoft.Office.Interop.Word API to detect event of opening a file by a user ?

我尝试了以下操作(显然它不起作用,因为它只是打开了Word Office应用程序)

i tried the following (obviously it doesn't work, since it's just opens a word office application)

using Word = Microsoft.Office.Interop.Word;
Word.Application oWord = new Word.Application(); 
oWord.Visible = true;
oWord.DocumentChange += new Word.ApplicationEvents4_DocumentChangeEventHandler(oWord_DocumentChange);
...

private void oWord_DocumentChange()
{
   Console.WriteLine("DocumentChange");
}

另外,我可能想使用Microsoft.Office.Interop.Word.Document,但不能. 我开始开发自己的方法,但是由于此api已经构建,因此似乎只是一种浪费. 任何帮助都会很棒..谢谢.

also, i wanted to maybe use Microsoft.Office.Interop.Word.Document, but couldn't. i started developing a method of my own, but its just seems to be a waste since this api is already build. any help will be great.. thanks.

推荐答案

您是否已尝试创建应用程序级插件.该加载项应具有检测到文档的第一个和最后一个更改所需的所有事件处理程序.

Have you already tried creating an Application level Add-in. That add-in should have all the event handlers you need to detect the first and last change to the document.

这篇关于检测用户何时打开单词文档以及何时键入单词文档(在c#中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆