creator
creator

Reputation: 1

DataSet to excel issue

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

Upvotes: 0

Views: 410

Answers (1)

Alan Stephens
Alan Stephens

Reputation: 579

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

Upvotes: 1

Related Questions