dimanche 18 août 2019

Excel file export nothing happens with no error

I have trying to export my data from my data access layer but nothing happens no error and not exported. it is kinda hard to know whats wrong because there's no error

I have tried this:

if (dt.Rows.Count > 0)
                            {
                                dgv.DataSource = dt;
                                dgv.DataBind();

                                Response.ClearContent();
                                Response.AppendHeader("content-disposition","attachement;filename=transaction.xls");
                                Response.ContentType = "application/excel";
                                StringWriter stringWritter = new StringWriter();
                                HtmlTextWriter htmlTextWritter = new HtmlTextWriter(stringWritter);

                                dgv.RenderControl(htmlTextWritter);
                                Response.Write(stringWritter.ToString());

                                HttpContext.Current.Response.Flush();
                                HttpContext.Current.Response.SuppressContent = true;
                                HttpContext.Current.ApplicationInstance.CompleteRequest();

but nothing happens.

i have tried this but also nothing:

   Response.Clear();
                        Response.Buffer = false;
                        Response.ContentType = "application/vnd.ms-excel";
                        Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xls", "TransactionReport"));
                        Response.Charset = "";

                        dgv.DataSource = dt;
                        dgv.DataBind();

                        dgv.RenderControl(osHtmlTextWritter);
                        Response.Write("Report Datw:" + DateTime.Now);
                        Response.Write(osStringWritter.ToString());
                        //Response.End();
                        HttpContext.Current.Response.Flush();
                        HttpContext.Current.Response.SuppressContent = true;
                        HttpContext.Current.ApplicationInstance.CompleteRequest();

                        dgv = null;
                        osStringWritter = null;
                        osHtmlTextWritter = null;

What i'm doing wrong ?




Aucun commentaire:

Enregistrer un commentaire