将gridview中的数据导出到excel中
来源:互联网 发布:oss js 上传文件 跨域 编辑:程序博客网 时间:2024/05/02 03:01
protected void Button1_Click(object sender, EventArgs e)
{
string strFileName = DateTime.Now.ToString("yyyyMMdd-hhmmss");
string style = @"<style> .text { mso-number-format:/@; } </style> ";
System.Web.HttpContext HC = System.Web.HttpContext.Current;
HC.Response.Clear();
HC.Response.Buffer = true;
//导出为excel
HC.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8) + ".xls");
HC.Response.ContentType = "application/vnd.xls";
//HC.Response.ContentType = "application/ms-excel";//设置导出文件的格式
Response.ContentEncoding = System.Text.Encoding.UTF8;//设置输出流为简体中文
#region 导出为word
//HC.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8) + ".doc");
//HC.Response.ContentType = "application/ms-word";//设置输出文件类型为Word文件。
#endregion
EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
this.GridView1.AllowPaging = false;
BindGridView();
this.GridView1.RenderControl(htw);
HC.Response.Write(style);
HC.Response.Write(sw.ToString());
HC.Response.End();
this.GridView1.AllowPaging = true;
BindGridView();
}
报错:类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内
解决:添加事件
public override void VerifyRenderingInServerForm(Control control)
{
}
报错:只能在执行 Render() 的过程中调用 RegisterForEventValidation
解决:将asp页面的
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="JBZ_DailyReport.aspx.cs" Inherits="_Default" %>
改成
<%@ Page Language="C#" EnableEventValidation = "false" AutoEventWireup="true" CodeFile="JBZ_DailyReport.aspx.cs" Inherits="_Default" %>
奋斗了一天终于弄出来,(*^__^*)
- 将gridview中的数据导出到excel中
- 将GridView中的数据导出到Excel / Word中
- 将GridView中的数据导出到Excel / Word中
- Gridview中的数据导出到excel中
- 将GridView中的数据导出到Excel,Word,Html
- asp.net 将GridView中的数据导出到Excel
- 将GridView控件数据导出到Excel中。
- 将dev gridview中数据原样导出到EXCEL
- 将 GridView 导出到 Excel 文件中
- 将 GridView 导出到 Excel 文件中
- 将GridView中数据导出为Excel
- 导出GridView中的数据到Excel
- GridView数据导出到Word/Excel中
- gridview 数据导出到excel中
- GridView数据导出到Excel中
- 将TDBGridEh中的数据导出到Excel中
- 将MsFlexGrid中的数据导出到Excel中
- 如何将DataGrid中的数据导出到Excel文件中
- linux smartctl 磁盘健康监测
- js取整数四舍五入
- Oracle中TO_DATE格式
- CSDN特别收录 --- 超强的指针 *一辈子都找不到的牛B贴
- 解决jquery和其他库的冲突
- 将gridview中的数据导出到excel中
- ORACLE之TO_DATE
- vc海量数据树控件使用总结
- 分页
- The current identity (NT AUTHORITY/NETWORK SERVICE) does not have write access to 'C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319
- 网络程序员须知
- 10.11.4-----iOS出4.2了.
- 书目
- oracle11g客户端-配置