将页面上的内容导出到Excel
2013-11-27 20:26
288 查看
<asp:Button ID="lkbExport" runat="server" Name="Save" Text="导出到excel" class="button_h_b"
Style="display: block" OnClick="lkbExport_Click" />
前台的导出按钮
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for
}
#region export excel linkbutton
protected void lkbExport_Click(object sender, EventArgs e)
{
//说明:earDiv 是页面上的div ,业就是你想要导出的这个div里边包括的内容,也可以是其它控件,也就是你给它什么控件,它就会把你这个控件里的内容导出到Excel中
if (year_list.Text.ToString().Trim() != "")
{
stryear = year_list.Text.ToString().Trim();
}
iniListPanel(stryear); //初始化页面的方法
//Catch缓存给权限
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AppendHeader("Expires ", System.DateTime.Now.AddMinutes(30).ToString());
HttpContext.Current.Response.AppendHeader("Pragma ", "public ");
HttpContext.Current.Response.AppendHeader("Cache-Control ", "must-revalidate, post-check=0, pre-check=0 ");
HttpContext.Current.Response.AppendHeader("Cache-Control ", "public ");
//HttpContext.Current.Response.Charset = "UTF-8";
//HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF7;
//HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=export"+DateTime.Now.Ticks.ToString()+".xls");
//HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.Charset = "GB2312";
Response.Write("<meta http-equiv=Content-Type content=text/html;charset=GB2312>");
Response.AppendHeader("Content-Disposition", "attachment;filename=export" + DateTime.Now.Ticks.ToString() + ".xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/vnd.xls";//设置输出文件类型为excel文件。 y
earDiv.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
this.yearDiv.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
} #endregion
Style="display: block" OnClick="lkbExport_Click" />
前台的导出按钮
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for
}
#region export excel linkbutton
protected void lkbExport_Click(object sender, EventArgs e)
{
//说明:earDiv 是页面上的div ,业就是你想要导出的这个div里边包括的内容,也可以是其它控件,也就是你给它什么控件,它就会把你这个控件里的内容导出到Excel中
if (year_list.Text.ToString().Trim() != "")
{
stryear = year_list.Text.ToString().Trim();
}
iniListPanel(stryear); //初始化页面的方法
//Catch缓存给权限
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AppendHeader("Expires ", System.DateTime.Now.AddMinutes(30).ToString());
HttpContext.Current.Response.AppendHeader("Pragma ", "public ");
HttpContext.Current.Response.AppendHeader("Cache-Control ", "must-revalidate, post-check=0, pre-check=0 ");
HttpContext.Current.Response.AppendHeader("Cache-Control ", "public ");
//HttpContext.Current.Response.Charset = "UTF-8";
//HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF7;
//HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=export"+DateTime.Now.Ticks.ToString()+".xls");
//HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.Charset = "GB2312";
Response.Write("<meta http-equiv=Content-Type content=text/html;charset=GB2312>");
Response.AppendHeader("Content-Disposition", "attachment;filename=export" + DateTime.Now.Ticks.ToString() + ".xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/vnd.xls";//设置输出文件类型为excel文件。 y
earDiv.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
this.yearDiv.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
} #endregion
相关文章推荐
- 将页面内容导出为excel或word
- JavaScript Web页面内容导出到Word、Excel
- javascript Web页面内容导出到Word、Excel
- Java读取Excel内容&jsp页面内容导出到Excel中
- ASP.NET页面内容导出为Excel
- JavaScript将Web页面内容导出到Word及Excel的方法
- asp.net table页面内容导出到Excel
- 导出页面内容为Excel格式
- JavaScript Web页面内容导出到Word、Excel (转载)
- JavaScript Web页面内容导出到Word、Excel
- JavaScript Web页面内容导出到Word、Excel
- 使用JavaScript将Web页面内容导出到Word、Excel
- 导出页面指定区域内容到Word/Excel
- jsp页面内容导出到Excel中
- JavaScript Web页面内容导出到Word、Excel
- ASP.NET页面内容导出为Excel
- 把页面Table表格内容导出为Excel-仅是当前页面上显示的table 分页未知(转载 略修改)
- JavaScript将Web页面内容导出到Word及Excel的方法
- Python处理unicode编码的txt文件(Python中文处理)——解决to_excel()和to_csv()导出文件内容为空的问题
- 将GridView导出到Excel并防止内容乱码