快速简洁将Gridview导出到EXCEL中
来源:互联网 发布:nsurlsessiond mac 编辑:程序博客网 时间:2024/06/06 12:54
将GridView中的数据导出到Excel中
1.需要重写VerifyRenderingInServerForm(Control control)方法
/// <summary> /// 导出Excel采用此方法 需要重写 /// </summary> /// <param name="control"></param> public override void VerifyRenderingInServerForm(Control control) { }
2.导出到Excel中的方法
public void ExcelAndManualSign(System.Web.UI.Control ctl, string strFileName) { HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + strFileName + ".xls"); HttpContext.Current.Response.Charset = "gb2312"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); //System.Text.Encoding.Default; HttpContext.Current.Response.ContentType = "application/ms-excel"; //设置输出流为简体中文 ctl.Page.EnableViewState = false; System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true); System.IO.StringWriter tw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw); ctl.RenderControl(hw); HttpContext.Current.Response.Write(tw.ToString()); HttpContext.Current.Response.End(); hw.Flush(); hw.Close(); tw.Flush(); tw.Close(); }
3.调用导入Excel的方法
protected void lbBtnToExcel_Click(object sender, EventArgs e) { if (GVContentList.Rows.Count == 0) { ScriptManager.RegisterStartupScript(GVContentList, this.GetType(), "", "alert('没有需要导出的数据');", true); return; } GVContentList.ShowHeader = true; GVContentList.Columns[5].Visible = false; GVContentList.GridLines = GridLines.Both; GVContentList.AllowPaging = false; //取消分页 导出所有数据 需要重新加载 if (cbISAll.Checked == true) { LoadGvlistbyMins(); } else { loadGvList(); } string fileName = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString(); ExcelAndManualSign(GVContentList, fileName); } public void LoadGvlistbyMins() { int count = 0; if(CheckForms.IsUnsignedInteger(this.txtNoTimeMin.Value)==false) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('输入的迟到分钟不符合!')", true); return; } string laterMin = this.txtNoTimeMin.Value; if (laterMin == "" || !cbISAll.Checked) laterMin = "0"; System.IFormatProvider format = new System.Globalization.CultureInfo("zh-CN", true); ScheduleInfoManage siMan = new ScheduleInfoManage(); DataTable dt = siMan.NoTimeExamCount(txtSTime.Value.Replace("-", ""), txtEtime.Value.Replace("-", ""), Convert.ToInt32(ddlStyle.SelectedValue), Convert.ToInt32(ddlJF.SelectedValue), ddlKSBQ.SelectedValue, laterMin); DataTable newdt = dt.Copy(); newdt.Clear(); this.GVContentList.DataSource = newdt; this.GVContentList.DataBind(); }
0 0
- 快速简洁将Gridview导出到EXCEL中
- 将 GridView 导出到 Excel 文件中
- 将 GridView 导出到 Excel 文件中
- 将gridview的内容导出到excel中去
- 将gridview的内容导出到excel中去
- 将gridview的内容导出到excel中去
- 下面代码实现将 GridView 导出到 Excel文件中。
- 将gridview的内容导出到excel中去
- 实现将 GridView 导出到 Excel文件中
- 将GridView的内容导出到Excel中(常见问题)
- 将gridview的内容导出到excel中去
- 将GridView的内容导出到Excel中
- 将gridview中的数据导出到excel中
- 将GridView控件数据导出到Excel中。
- 将GridView的内容导出到Excel中
- 将GridView中的数据导出到Excel / Word中
- 将GridView中的数据导出到Excel / Word中
- 将dev gridview中数据原样导出到EXCEL
- 第14周项目1折腾二维数组
- POSIX 多线程程序设计
- RSA密钥的数据类型转换:由合法的string到PublicKey或PrivateKey
- 简单实现修改密码校验器
- Qt 窗体最大化、最小化时的事件触发
- 快速简洁将Gridview导出到EXCEL中
- linux读取文件内容
- javascript B,KB,MB等单位换算
- 国内外大型SNS网站后台架构对比
- 宣布 Azure Backup 支持备份 Windows Server 2008
- 大型网站的负载均衡器、db proxy和db
- Bootstrap学习笔记
- 【SSH三大框架】Hibernate基础第十二篇:load()懒加载分析以及一对一、一对多、多对一、多对多懒加载的分析
- Java 1.6 新特性