开发者

DataSet to excel issue

开发者 https://www.devze.com 2023-03-01 01:37 出处:网络
I am Using the below code to save a dataset to excel and everything is working fine and the data is stored in the excel , but when i mail the excel the excel got on the other end is without any data (

I am Using the below code to save a dataset to excel and everything is working fine and the data is stored in the excel , but when i mail the excel the excel got on the other end is without any data (entries) in it.

        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());
            }       
        }


There's quite a lot of questions tagged about this. Try https://stackoverflow.com/questions/2041417/export-to-excel-in-c for starters

0

精彩评论

暂无评论...
验证码 换一张
取 消