在ASP.NET中,我需要将数据库文件保存成XLS格式,但是在保存过程中,不能弹出保存文件对话框,请各位高手帮忙解决一下,谢谢了!
//执行保存
    protected void save(DataSet ds, string title)
    {
        Application xlApp = new ApplicationClass();
        xlApp = ExportDataGridToExcel(ds, title);
        xlApp.Visible = true;
        
        xlApp.ActiveWorkbook.SaveAs("7.XLS", XlFileFormat.xlExcel9795, null, null, false, false, XlSaveAsAccessMode.xlNoChange, null, null, null, null, null);
        xlApp = null;
        GC.Collect();
        GC.WaitForPendingFinalizers();
    }

解决方案 »

  1.   

    private void ResponseExcel(string fileName, System.Web.HttpResponse response, string filePathCash)
        {
            response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            response.Charset = "utf-8";
            response.AddFileDependency(fileName);
            response.ContentType = "text/xls";
            response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.WriteFile(filePathCash);
            response.End();
        }
      

  2.   

    Response.ContentType = "application/vnd.ms-excel";
    Response.AppendHeader("Content-Disposition","attachment; filename="+ System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes("港口代码.xls")) );
      

  3.   

    Response.ContentType = "application/vnd.ms-excel";
    Response.AppendHeader("Content-Disposition","attachment; filename="+ System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes("港口代码.xls")) );
      

  4.   

    但是在保存过程中,不能弹出保存文件对话框========这是流氓软件,呵呵========或者可以做成ActiveX,偶现在就做了一个...
      

  5.   

    客户端弹对话框比较难,用ActiveX,调用activeform
      

  6.   

    函数返回字符串指向文件保存位置,然后response输出
    Response.Redirect("http://test/123.xls")