这样的,用户点击WEB页面上的“导出成EXCEL”按钮后将DataTable中的数据导成XLS文件并保存在用户所选择的目录。
现在可以导出成XLS了,怎么保存在用户选的目录呢?
请给个详细点的码好吗。谢谢。

解决方案 »

  1.   

    生成一个xsl文件 让客户下载,客户保存在什么地方跟web无关。
      

  2.   

    修改Response的ContentType属性,让用户下载xls文件
      

  3.   

    直接输出到response stream里去
      

  4.   


    private void ExportExcel(string fileName)
    {
        StringWriter sw = new StringWriter();
        sw.WriteLine(fileContent);
        Response.AddHeader("Content-Disposition","attachment;filename="+fileName+"");
        Response.ContentType="appication/ms-excel";
        Response.ContentEncoding=System.Text.Encoding.GetEncoding("UTF8");
        Response.Write(sw);
    }