请教高手:“Application是不明确的引用”时什么意思?

reanna 2002-12-06 11:57:13
写一个WinForm打开Word的小程序,用按钮触发打开的事件
编译时报2个错:
1、“C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OpenWord\Form1.cs(87): “Application”是不明确的引用


2、“C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OpenWord\Form1.cs(95): 重载“Open”方法未获取“15”参数


请教高手如何解决,谢谢!

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Word;//=Microsoft.Office.Interop.Word;
using System.Reflection;

namespace OpenWord
{
public class Form1 : System.Windows.Forms.Form
{
Word._Application oWapp;
Word._Document oDoc;
object oPath="c:\a.doc";//文件路径;
object misOpt = System.Reflection.Missing.Value;

private System.Windows.Forms.Button button1;

private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(96, 48);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1()); //第1个报错

}

private void button1_Click(object sender, System.EventArgs e)
{
oWapp = new Word.Application();
oWapp.Visible = true;

oDoc = (Word._Document)(oWapp.Documents.Open(ref oPath,ref misOpt,ref misOpt,ref misOpt,ref misOpt,ref misOpt,ref misOpt,ref misOpt,ref misOpt,ref misOpt,ref misOpt,ref misOpt,ref misOpt,ref misOpt,ref misOpt)); //第2个报错

}
}
}
...全文
149 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
reanna 2002-12-11
  • 打赏
  • 举报
回复
其实就是想打开Word文件
用一个方法就好了System.Diagnostics.Process.Start(strPath);
烈马狂生 2002-12-09
  • 打赏
  • 举报
回复
我不知道了,而且是实在不知道!很迷惑
saucer 2002-12-06
  • 打赏
  • 举报
回复
try

object oPath= @"c:\a.doc";

or

object oPath="c:\\a.doc";
reanna 2002-12-06
  • 打赏
  • 举报
回复
我用的就是office2000
烈马狂生 2002-12-06
  • 打赏
  • 举报
回复
我知道了,你这个问题我昨天刚碰到。

我的情况是:

我开发用的是office2000,运行正常。

但当在装有officexp的机器上运行,debug版时错误。 运行realese版正常。

因为offiec2000用的库是 9.0
xp 用的是10.0

我不知道和你的情况是不是类试
reanna 2002-12-06
  • 打赏
  • 举报
回复
还是报错:
C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OpenWord\Form1.cs(98): 重载“Open”方法未获取“13”参数

你写的System.Reflection.Missing.Value
之前我已经声明过了object misOpt = System.Reflection.Missing.Value;
烈马狂生 2002-12-06
  • 打赏
  • 举报
回复
Open(strTemplateName,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value);

reanna 2002-12-06
  • 打赏
  • 举报
回复
第一个问题解决了,谢谢!
请问第二个问题有什么办法吗?

“C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\OpenWord\Form1.cs(95): 重载“Open”方法未获取“15”参数

saucer 2002-12-06
  • 打赏
  • 举报
回复
Application.Run(new Form1());
===>
System.Windows.Forms.Application.Run(new Form1());
reanna 2002-12-06
  • 打赏
  • 举报
回复
还是一样的,还有什么办法吗?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧