调用上一文章写的导出gridview Excel 类

       protected void btnexcel_Click(object sender, EventArgs e)
    {
          BindData();
        string filename = DateTime.Now.ToString("yyyyMMddhhmmss");
        Common.Lib.GridViewExportExcel outep = new Common.Lib.GridViewExportExcel(Response);
        outep.Export(filename, gvshow);
    }

    protected void gvshow_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("style", "vnd.ms-excel.numberformat: @");  //这句的作用是如果导出的数字前面有零,不加这句话,前面的零将会被去掉
        }
    }

原文地址:https://www.cnblogs.com/lgxll/p/2812291.html