Sumit Banglorkar

Sumit Banglorkar

  • NA
  • 38
  • 29.6k

Excel Issues

Jul 14 2013 2:53 AM
Hi Friends,
Using Asp.net & C#.
I am generating Excel File from Gridview, In gridview i have last three columns which is button like View,Update & Delete. I don't need that button columns is to be generate in File, pls give me solutions how to do this.
Thanks in advanced...
Here is my code...(.cs)

if (GridViewWorkDisciplineMaster.Rows.Count == AppConstants.EMPTY_STRING_LEN)
            {
                ChangeLabelColor(lblerror, "No Records Found to Export", AppConstants.BOOL_TRUE);
                return;
            }
            else
            {
                Response.Clear();
                Response.Buffer = AppConstants.BOOL_TRUE;
                Response.AddHeader("content-disposition", "attachment;filename=WorkDisciplineMaster_" + DateTime.Now.ToString("dd/MM/yyyy") + ".xls");
                Response.Charset = AppConstants.EMPTY_STRING;
                Response.ContentType = "application/vnd.ms-excel";
                StringWriter sw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(sw);
                if (isAllDataExport == AppConstants.BOOL_TRUE)
                {
                    BindData();
                }
                else if (isSearchDataExport == AppConstants.BOOL_TRUE)
                {
                    btnSearch_Click(sender, e);
                }
                else if (isLikeDataExport == AppConstants.BOOL_TRUE)
                {
                    btnLike_Click(sender, e);
                }
                GridViewWorkDisciplineMaster.AllowPaging = AppConstants.BOOL_FALSE;
                GridViewWorkDisciplineMaster.DataBind();
                //Change the Header Row back to white color
                GridViewWorkDisciplineMaster.HeaderRow.Style.Add("background-color", "#FFFFFF");
                //Apply style to Individual Cells
                GridViewWorkDisciplineMaster.HeaderRow.Cells[0].Style.Add("background-color", "green");
                GridViewWorkDisciplineMaster.HeaderRow.Cells[1].Style.Add("background-color", "green");
                //GridViewWorkDisciplineMaster.HeaderRow.Cells[2].Style.Add("background-color", "green");
                //GridViewWorkDisciplineMaster.HeaderRow.Cells[3].Style.Add("background-color", "green");
                for (int i = 0; i < GridViewWorkDisciplineMaster.Rows.Count; i++)
                {
                    GridViewRow row = GridViewWorkDisciplineMaster.Rows[i];
                    //Change Color back to white
                    row.BackColor = System.Drawing.Color.White;

                    //Apply text style to each Row
                    row.Attributes.Add("class", "textmode");

                    //Apply style to Individual Cells of Alternating Row
                    if (i % 2 != 0)
                    {
                        row.Cells[0].Style.Add("background-color", "#C2D69B");
                        row.Cells[1].Style.Add("background-color", "#C2D69B");
                        //row.Cells[2].Style.Add("background-color", "#C2D69B");
                        //row.Cells[3].Style.Add("background-color", "#C2D69B");
                    }
                }
                GridViewWorkDisciplineMaster.RenderControl(hw);

                //style to format numbers to string
                string style = @"<style> .textmode { mso-number-format:\@; } </style>";
                Response.Write(style);
                Response.Output.Write(sw.ToString());
                Response.Flush();
                Response.End();
            }




And also i need to give heading like
1. name of company
2. name of report
3. print date
4. page no.

Pls help me out...

Regards,
Sumit...


Answers (3)