采用反射实现后期绑定。具体代码,呆会给出。

解决方案 »

  1.   

    这是具体的通过后期绑定调用Excel的代码,调了整整一下午.
    才实现简单的打开Excel并显示的功能.采用这种方法真是累.
    还需要一点点VC++的经验.下面是具体的代码:using System;
    using System.Reflection;
    using System.Windows;
    using System.Windows.Forms;class TestLateBound:System.Windows.Forms.Form
    {
    private Button myButton;
    public  TestLateBound()
    {
    myButton=new Button();
    myButton.Text="调用EXCEL";
    myButton.Location=new System.Drawing.Point(100,100);
    myButton.Click+=new System.EventHandler(TestBound);

    this.Controls.Add(myButton);
    this.Text="测试后期绑定 Excel Application";

    }

    public void TestBound(object sender,System.EventArgs ef)
    {
    Type myExcel;
    myExcel=Type.GetTypeFromProgID("Excel.Application");

    object objExcel;
    objExcel=Activator.CreateInstance(myExcel);

    object[] param=new object[1];
    param[0]=true;
    try
    {
    myExcel.InvokeMember("Visible",BindingFlags.SetProperty,null,objExcel,param);
    }
    catch (Exception e)
    {
    MessageBox.Show (e.ToString());
    } }
    public static void Main()
    {
    Application.Run(new TestLateBound());
    }
    }