DataSet优秀的问题

时间:2011-04-28 08:56:57

标签: c# asp.net datagrid export-to-excel

我正在使用以下代码将数据集保存到excel并且一切正常并且数据存储在excel中,但是当我邮寄excel时,另一端的excel没有任何数据(条目)它

        HttpResponse response = HttpContext.Current.Response;

        // first let's clean up the response.object
        response.Clear();
        response.Charset = "";
        Response.ContentEncoding = System.Text.Encoding.Default;


        using (StringWriter sw = new StringWriter())
        {
            using (HtmlTextWriter htw = new HtmlTextWriter(sw))
            {
                DataGrid dg = new DataGrid();
                dg.DataSource = DS.Tables[0];
                dg.DataBind();
                dg.RenderControl(htw);
                string sPath = @"E:\CR-12\Test.xls";
                File.WriteAllText(sPath, sw.ToString());
            }       
        }

1 个答案:

答案 0 :(得分:1)

有很多关于此问题的问题。首先尝试https://stackoverflow.com/questions/2041417/export-to-excel-in-c