请问我下面的代码运行后为什么会出现这样的错误:
“Application”是不明确的引用
Application.Run(new Form1()); //这行出错,“Application”是不明确的引用
我把using Excel;去掉又正常了?
请问高手为什么会这样的????=============================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Excel;
namespace WindowsApplication2
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1()); //这行出错,“Application”是不明确的引用
} private void Form1_Load(object sender, System.EventArgs e)
{
CreateExcel();
} public static void CreateExcel()
{
MessageBox.Show("asd");
for(int i = 0 ; i<1 ; i++)
{
string staFile = "D:\\test\\x";
System.Reflection.Missing miss = System.Reflection.Missing.Value;
Excel.ApplicationClass m_objExcel = new Excel.ApplicationClass();
m_objExcel.Visible = false;
Excel.Workbooks m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
Excel.Workbook m_objBook = (Excel.Workbook)(m_objBooks.Add(miss));
Excel.Worksheet m_objSheet = (Excel.Worksheet)m_objBook.ActiveSheet;
//向Excel文件中写入数据
Excel.Range er = m_objSheet.get_Range((object)"A1",System.Reflection.Missing.Value);
er.Value2 = "dfadfa"; m_objBook.SaveAs(staFile+i.ToString()+".xls", miss, miss, miss, miss,miss, Excel.XlSaveAsAccessMode.xlNoChange, miss,miss,miss, miss, miss);
m_objBook.Close(false, miss, miss);
m_objBooks.Close();
m_objExcel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(er);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objExcel);
GC.Collect();
}
}
}
}
解决方案 »
- 请问怎样使richbox的下拉条拉倒最下
- panel内窗体跟随 panel 变化而变化
- DATAGRIDVIEW显示问题 急急!!
- windows服务问题
- 如何判断一对象是否包括其它对象数组
- 请英语高手准确翻译一小段英文。谢谢!
- 请高手帮帮忙给个实例 C#.NET TCP实现获取远程计算机IP地址同端口
- 高分请教c#+asp.net WebService 和关于net Remoting的问题,问题解决后马上结贴!谢谢!
- 求一本C#的GUI编程的好书
- CRC校验改写
- 关于如何把DATATABLE中的数据安一定格式打印的问题(最好能给个例子)谢谢
- Rational XDE Developer Plus怎么进行重构?
是引入命名空间,
这个命名空间不是系统的,可能是程序定义的,也可能是程序引用的.dll,
现在找不到这个命名空间,所以运行会出错,而你这段程序没有用到这个命名空间里的方法,所以去掉也没有关系
System.Windows.Forms.Application.Run(new Form1());
http://www.cnblogs.com/renyu732/archive/2005/06/15/174866.html