gridview导出Execl
来源:互联网 发布:办公楼网络布线方案 编辑:程序博客网 时间:2024/05/22 00:38
#region btnExcel_Click
/// <summary>
/// 把数据导出到Excel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnExcel_Click(object sender, EventArgs e)
{
if (gridView.Rows.Count > 0)
{
gridView.AllowPaging = false; //清除分页
string sDateFrom = Convert.ToDateTime(this.txtDayDateFrom.Text).ToString("yyyyMMdd");
string sDateTo = Convert.ToDateTime(this.txtDayDateTo.Text).ToString("yyyyMMdd");
BindGridView(sDateFrom, sDateTo);
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
gridView.EnableViewState = false;
// Deshabilitar la validación de eventos, sólo asp.net 2
page.EnableEventValidation = false;
// Realiza las inicializaciones de la instancia de la clase Page que requieran los dise?adores RAD.
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(gridView);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=data.xls");
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sb.ToString());
Response.End();
gridView.AllowPaging = true; //清除分页
sDateFrom = Convert.ToDateTime(this.txtDayDateFrom.Text).ToString("yyyyMMdd");
sDateTo = Convert.ToDateTime(this.txtDayDateTo.Text).ToString("yyyyMMdd");
BindGridView(sDateFrom, sDateTo);
}
else
{
Response.Write("<script>alert('请先查询!')</script>");
}
}
#endregion
- 用GridView导出Execl
- GridView导出Execl
- Gridview导出Execl样式
- gridview导出Execl
- GridView导出Execl的时候移去不要的欄位
- 把GridView的列表数据导出为Execl表格文件
- GridView导出Execl时报错RegisterForEventValidation的错误提示
- 导出execl
- execl导出
- EXECL导出
- execl导出
- VS2005 C# WebForm 中Gridview 导出数据到Execl 或Word常见问题及解决办法。
- 把数据从gridview导出到execl中的一点小收获
- 导出Execl(电子表格)总结
- C#导出Execl汇总
- 导出Execl方法汇总
- php导出execl
- 数据导出到execl
- 编程珠玑——AVL树
- Mysql报错:Result consisted of more than one row
- struts2与Spring3集成中Action的自动装配不起作用 annotation注入不起作用
- OpenCV中Lab空间简介及RGB转Lab
- 编程珠玑——多路归并排序
- gridview导出Execl
- Linux-Android启动之Init进程前传
- 学习shell之一:sh.sh
- 关于Perl中while和if后面的语句段执行过程的区别
- Android Wifi BT的工作流程和porting(精)
- Android中读取properties文件
- SQLServer2000 中危险存储过程删除及恢复方法
- STL
- python 常用正则匹配