返回首页

IM出口GridView控件到Excel中,但它不工作,我DNT knw为什么?
通过使用-GT的代码是

try

        {

            Response.Buffer = true;

            Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.xls"));

            Response.ContentType = "application/ms-excel";

            StringWriter sw = new StringWriter();

            HtmlTextWriter htw = new HtmlTextWriter(sw);

            gv_appt.AllowPaging = false;

            // gv_Employes.DataBind();

            //Change the Header Row back to white color

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

            //Applying stlye to gridview header cells

            for (int i = 0; i < gv_appt.HeaderRow.Cells.Count; i++)

            {

                gv_appt.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1");

            }

            int j = 1;

            //This loop is used to apply stlye to cells based on particular row

            foreach (GridViewRow gvrow in gv_appt.Rows)

            {

                gvrow.BackColor = Color.White;

                if (j <= gv_appt.Rows.Count)

                {

                    if (j % 2 != 0)

                    {

                        for (int k = 0; k < gvrow.Cells.Count; k++)

                        {

                            gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");

                        }

                    }

                }

                j++;

            }

            foreach (GridViewRow row in gv_appt.Rows)

            {

               

                LinkButton appgenrt = (LinkButton)row.FindControl("lbtn_apptGenerate");

                LinkButton email = (LinkButton)row.FindControl("lbtn_email");

                LinkButton edit = (LinkButton)row.FindControl("btn_editappt");

                LinkButton del = (LinkButton)row.FindControl(" btl_aapdlt");

                appgenrt.Visible = false;

                email.Visible = false;

                edit.Visible = false;

                del.Visible = false;

                gv_appt.Columns[7].Visible = false;

                gv_appt.Columns[8].Visible = false;

                gv_appt.Columns[9].Visible = false;

                gv_appt.Columns[10].Visible = false;

            }

            gv_appt.RenderControl(htw);

            Response.Write(sw.ToString());

            Response.End();

        }

        catch { }
:8387468 |会员

回答

评论会员: 时间:2
c