日期:2014-05-18  浏览次数:20446 次

在.net中如何打开调用excel程序打开一个excel文件? 就像直接双击这个文件一样。
在.net中如何打开调用excel程序打开一个excel文件?   就像直接双击这个文件一样。

------解决方案--------------------
using System;


namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string filePath=@ "C:\test.xls ";
object missing=System.Reflection.Missing.Value;

Excel.ApplicationClass excelApp=new Excel.ApplicationClass();
Excel.Workbook workbook=excelApp.Workbooks.Open(filePath,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing);
excelApp.Visible=true;
}
}
}


------解决方案--------------------
System.Diagnostics.Process process = new System.Diagnostics.Process();

process.StartInfo.FileName = @ "c:\a.excel ";

process.Start();


------解决方案--------------------
asp.net在后台调用的excel是没有界面的.
------解决方案--------------------
using System;
using System.Reflection;
using System.Windows;
using System.Windows.Forms;

class TestLateBound:System.Windows.Forms.Form
{
private System.Windows.Forms.Button myButton;

public TestLateBound()
{
myButton=new Button();
myButton.Text= "调用EXCEL ";
myButton.Location=new System.Drawing.Point(100,100);
myButton.Click+=new System.EventHandler(TestBound);

Controls.Add(myButton);
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); //和VC++中差不多,需要将参数封装为数组传入
}
catch (Exception e)
{
MessageBox.Show (e.ToString());
}

}

public void InitializeComponent()
{
myButton = new System.Windows.Forms.Button();
SuspendLayout();
//
// myButton
//
myButton.Location = new System.Drawing.Point(128, 72);
myButton.Name = "myButton ";
myButton.TabIndex = 0;
myButton.Text = "button1 ";
myButton.Click += new System.EventHandler(myButton_Click);
//
// TestLateBound
//
AutoScaleBaseSize = new System.Drawing.Size(6,14);
ClientSize = new System.Drawing.Size(292,266);
Controls.Add(myButton);
Name = "TestLateBound ";
Load+=new EventHandler(TestLateBound_Load);
ResumeLayout(false);
}

public static void Main()
{
Application.Run(new TestLateBound());
}

private void myButton_Click(object sender, System.EventArgs e)
{

}