导出Excel
来源:互联网 发布:兰博德网络加速 编辑:程序博客网 时间:2024/06/18 14:12
Response.Clear();
Response.Write("<table><tr>.....<table">);
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType="Application/vnd.ms-excel";
Response.AddHeader("Content-Disposition","attachment;filename=ReqForQuote.xls");
Response.End();
=======================================================
#region 导出Excel
protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();
if (!string.IsNullOrEmpty(temp))
{
Response.Write(temp);
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "Application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=Excel.xls");
Response.End();
}
else
{
Response.Write("<script>alert('导出前请先统计!')</script>");
}
}
#endregion
==================================================
ASP.net:
using System.IO;
public partial class admin_user_excel2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["admin_login"] == null)
{
Response.Redirect("../login.aspx");
}
try
{
if (Request.Cookies["sql_wj_cx"] == null)//无cookie
{
Response.Write("<script>window.location='userList.aspx';</script>");
}
else//读取cookie
{
HttpCookie cookies = Request.Cookies["sql_wj_cx"];
string sql_user = cookies.Values["sql_str_wj"];
DataBase db = new DataBase();
this.GridView1.DataSource = db.FILL(sql_user).Tables[0];
this.GridView1.DataBind();
}
string day = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
ExportToExcel("application/ms-excel", "591win调查_" + day + ".xls");
Response.Write("<script>alert('导出Excel成功!');window.location='userList.aspx';</script>");
}
catch { }
finally
{
Response.Write("<script>window.location='userList.aspx';</script>");
}
}
public void ExportToExcel(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;//UTF8
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Output.Write(tw.ToString());
Response.Flush();
Response.End();
}
}
- 导出EXCEL
- Excel导出
- 导出Excel
- 导出EXCEL
- 导出Excel
- EXCEL导出
- 导出Excel
- 导出excel
- 导出excel
- EXCEL导出
- 导出excel
- 导出Excel
- Excel导出。
- 导出excel
- Excel 导出
- 导出excel
- 导出excel
- 导出excel
- TUXEDO配置常见问题及解决方法
- 女友7.0升级为老婆1.0时发生的BUG
- java 中 set map table list 的总结
- 少数Windows7和Vista用户无法正常上网的解决办法
- 随笔NODE
- 导出Excel
- 过滤js脚本
- 取得路径的各种方法
- java创建Xml笔记
- java删除文件或文件夹的方法
- 如何寫GPS定位的程式碼 C# VS2005 Sample Code
- 警惕operator =
- Java EL系列-3.0.JUEL基本类
- 用Jsp输出Word,PDF等文件时进行的设置