Convert ASP.NET datatables to different Excel SHEETS

Asked

Viewed 459 times

2

How can I create more than one sheets converting different datatable for excel? My code:

DataTable dt = new DataTable();

        dt = Tr.Get();
        GridView x = new GridView();
        x.DataSource = dt;
        x.DataBind();
        Response.Clear();
        x.HeaderStyle.Font.Size = 8;
        x.RowStyle.Font.Size = 10;

        Response.AddHeader("content-disposition", "attachment;filename=s.xls");
        Response.ContentType = "application/excel";

        StringWriter stringWriter = new StringWriter();
        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);

        x.RenderControl(htmlTextWriter);

        Response.Write(stringWriter.ToString());

        Response.End();
  • You can use Oledb to create the Excel document: http://www.connectionstrings.com/excel/. I don’t know if it works in web applications.

1 answer

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.