首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

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

在.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)
{

}



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

}


}
[解决办法]
不用那么麻烦
<script>
function OpenFile()
{
openDocObj = new ActiveXObject( "SharePoint.OpenDocuments.2 "); // 为了兼容Office XP,可以创建“SharePoint.OpenDocuments.1”
openDocObj.EditDocument( "http://10.2.55.7/CreateWindowsUser/aaa/totalEnd.xls ");
}
</script>
<input type=button value=打开Excel文件 onclick= "OpenFile(); ">


[解决办法]
在本地是可以用Process 打开的,客户端不行,js还打不开execl,除非做个插件,把文件下到本地,然后插件调用execl打开文件。不知道vbscript行不行,我不懂
[解决办法]
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType= "application/octet-stream ";
Response.AppendHeader( "Content-Disposition ", "attachment;filename= " +HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.UTF8));
Response.AppendHeader( "Content-Length ",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);

热点排行