如果在页面上显示的是Excel文档,当我浏览者打开这个Excel链接的时候,能不能调用客户端的Excel来打开它,而不是在浏览器中打开这个Excel文件.....

解决方案 »

  1.   

    刚刚做过一个,我用的是曲线救国的办法。
    1、在服务器端将数据写到excel文件里,定好文件名,保存起来。
    #region 将模板文件复制到一个新文件中
    string root = System.Web.HttpContext.Current.Request.MapPath("../report_templet/");
    string oldfilename=root+ "\\T_Form009.xls";

    string filename = "../report_files/Form009_SC_"+sIPID+".xls";
    string filename_map=System.Web.HttpContext.Current.Request.MapPath(filename);
    string str_Mess="";
    FileInfo mode=new FileInfo(oldfilename);object missing=Missing.Value;
    GC.Collect();
    Excel.Application myExcel=new Excel.Application();
    //打开新文件
    myExcel.Application.Workbooks.Open(filename_map,missing,missing,missing,missing,
    missing,missing,missing,missing,missing,missing, missing,missing); 
    Excel.Workbook myBook=myExcel.Workbooks[1];
    Excel.Worksheet curSheet = (Excel.Worksheet)myBook.Sheets[1];
    //写数据到Excel
    #region 保存文件、關閉Excel,並回收資源
    myBook.Save();
    myBook.Close(false, null,null);
    myExcel.Quit();
    System.Runtime.InteropServices.Marshal.ReleaseComObject(myBook);
    System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel);
    myBook = null;
    myExcel = null;
    GC.Collect();
    #endregion
    string UrlFiles="http://"+Request.ServerVariables["local_Addr"].ToString()+"/epay"+filename.Replace("\\","@@").Replace("..","");
    Response.Write("<Script>window.open('../OpenExcel.asp?urlfile="+UrlFiles+"');</Script>");
    2、做了一个asp文件
    <%@LANGUAGE="VBSCRIPT"%>
    <%
    response.Expires=0
    urlfile = replace(Request("urlfile"),"@@","/")
    '事先把Url中的"/"改为"@@"
    response.Write("如果不能启动 MS Excel,需要您的電腦安裝MS Excel 2000,<br>並修改 INTERNET EXPLORER 的安全性,<BR> 修改方法:打開 <BR> TOOLS --> <BR> INTERNER OPTION --> <BR> 安全 <BR> 選[自定層級]<br> 針對[起始但ActiveX控制項不標示為安全] 選[提示]。")%><script language="VBScript">
    Set xlApp = CreateObject("EXCEL.APPLICATION")
    xlApp.visible=true
    Set xlbook = xlApp.Workbooks.Open("<%=urlfile%>") 
    Set xlsheet = xlbook.Worksheets(1)
    window.close()
    </script>