Ramco Ramco

Ramco Ramco

  • 450
  • 3k
  • 424k

Export to excel

May 20 2023 7:04 AM

Hi

  I have below code & i want TextBox first column not to be exported. After export file also attached

protected void LinkButtonExport_Click(object sender, EventArgs e)
        {
            try
            {
                Response.ClearContent();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "SessionsBookPlanning.xls"));
                Response.ContentType = "application/ms-excel";
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
                grdPlanning.AllowPaging = false;
                GetData();

                grdPlanning.HeaderRow.Style.Add("background-color", "#FFFFFF");

                for (int i = 0; i < grdPlanning.HeaderRow.Cells.Count; i++)
                {
                    grdPlanning.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");
                }
                grdPlanning.RenderControl(htw);
                Response.Write(sw.ToString());
                Response.End();
            }
            catch (Exception ex)
            {
                Utility.SaveErrorLog(ex.Message, System.IO.Path.GetFileName(Request.Path), System.Reflection.MethodBase.GetCurrentMethod().Name, Convert.ToInt32(hdfLoginCode.Value));
                ShowMessage("Oops...", ex.Message, "error");
            }
        }

Thanks


Answers (1)