请求解释此代码 [英] pleaes explain this code

查看:90
本文介绍了请求解释此代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释什么是ref nullObj和doc.ActiveWindow



 Word.ApplicationClass wordApp =  new  Word.ApplicationClass(); 
object nullObj = System.Reflection.Missing.Value;
object roObj = true ;
object objFile = docPath;

尝试
{
Word.Document doc = wordApp.Documents.Open( ref objFile,
ref nullObj, ref roObj, ref nullObj, ref nullObj, ref nullObj,
ref nullObj, ref nullObj, ref nullObj, ref nullObj, ref nullObj,
ref nullObj, ref nullObj, ref nullObj, ref nullObj, ref nullObj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject tmpData = Clipboard.GetDataObject();
string docText = tmpData.GetData(DataFormats.Text).ToString();

(...)
}
catch (例外情况)
{
MessageBox.Show(ex.Data);
}

解决方案

这里使用System.Reflection.Missing.Value来告诉该方法使用默认值方法执行时的参数值。您最好阅读文档以获取更多信息。

Missing.Value Field [ ^ ]

缺少类 [ ^ ]

doc.ActiveWindow是当前关注的窗口,如果没有窗口打开,你将获得异常。 阅读本文 [ ^ ]。

Can someone explain whats ref nullObj and doc.ActiveWindow

Word.ApplicationClass wordApp = new Word.ApplicationClass();
   object nullObj = System.Reflection.Missing.Value;
   object roObj = true;
   object objFile = docPath;

   try
   {
       Word.Document doc = wordApp.Documents.Open(ref objFile,
           ref nullObj, ref roObj, ref nullObj, ref nullObj, ref nullObj,
           ref nullObj, ref nullObj, ref nullObj, ref nullObj, ref nullObj,
           ref nullObj, ref nullObj, ref nullObj, ref nullObj, ref nullObj);
       doc.ActiveWindow.Selection.WholeStory();
       doc.ActiveWindow.Selection.Copy();
       IDataObject tmpData = Clipboard.GetDataObject();
       string docText = tmpData.GetData(DataFormats.Text).ToString();

         (...)
   }
   catch (Exception ex)
   {
       MessageBox.Show(ex.Data);
   }

解决方案

System.Reflection.Missing.Value is used here for telling that method to use default parameter values when method execution. You better read the documentation for more information.
Missing.Value Field[^]
Missing Class[^]
doc.ActiveWindow is the window which currently focused, you will get exception if no window open. read this[^].


这篇关于请求解释此代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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