我在vs中操作Word,最后要关闭Word文件,在vs2003中正确,最近升级到2005,去报错,代码如下:
Word.Application myApp=null;
Word.Document myDoc=null;
myApp=new Word.ApplicationClass();
object ob=(object)p_FileName;
myDoc=myApp.Documents.Open(ref ob,ref Nothing,ref Nothing,ref Nothing,ref Nothing,
ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,
ref Nothing,ref Nothing);
myApp.Visible=true;关闭的代码如下:
myDoc.Close(ref bTrue,ref Nothing,ref Nothing);
编译关闭代码时,出现如下警告:警告 1 方法“Word._Document.Close(ref object, ref object, ref object)”和非方法“Word.DocumentEvents_Event.Close”之间存在二义性。将使用方法组。 F:\开发工程\公用工具\Lqjt\frmCommDataPro.cs 2362 10 Lqjt应该如何处理?

解决方案 »

  1.   

    我做的操作Word 的程序也重原来的VS2003升级到VS2005里,但是没有出现任何问题.
    只不过我是把所有操作Word的代码全部封装成方法,放到一个DLL里的.这个DLL是用VS2003编译的.很方便.
      

  2.   

    我用的是word2000中的Ole控件,我计划找个word2003,然后tlimp一下。
      

  3.   

    我也是用的WORD2000的OLE呀.
    本来我也是准备用2003的,但是考虑到版本问题也就放弃了.
    因为用2003的组件,生成 的Word文档在word2003以下的版本里打不开.
      

  4.   

    问题解决了,定义变量时用:
    Word.ApplicationClass WordApp
    代替题中的Word.Application myApp
    用Word.DocumentClass WordDoc
    代替题中的Word.Document WordDoc
    在打开文件时用强制转换一下:
    myDoc=(Word.DocumentClass )myApp.Documents.Open(ref ob,ref Nothing,ref Nothing,ref Nothing,ref Nothing,
    ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,
    ref Nothing,ref Nothing);
    myDoc=(Word.DocumentClass )……,是强制转换的,代码就没有问题了
      

  5.   

    没有这么麻烦吧:我把我的打开和保存代码发给你试试:
    private Word.ApplicationClass oWordApplic;
    private Word.Document oDoc;
    public void Open(string strFileName)
    {
    object fileName = strFileName;
    object readOnly = false;
    object isVisible = true;
    object missing = System.Reflection.Missing.Value; oDoc = oWordApplic.Documents.Open(ref fileName, ref missing, ref missing, 
    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, 
    ref missing, ref missing, ref missing); oDoc.Activate();
    } public void OpenFromTemplate(string strTemplate)
    {
    object missing = System.Reflection.Missing.Value;
    object oTemplate = strTemplate;
    object oVisible = true;
    oDoc = oWordApplic.Documents.Add(ref oTemplate, ref missing, ref missing, ref missing); oDoc.Activate();
    }public void Quit( )
    {
    object missing = System.Reflection.Missing.Value;
    oWordApplic.Quit(ref missing, ref missing, ref missing);
    oWordApplic=null;
    GC.Collect();
    GC.WaitForPendingFinalizers();
    }