在web中如何实现生成EXCEL表格?我想实现把数据填充到excel模板文件中去,把生成的临时EXCEL
文件提供给客户端下载!希望大家提供一些例子!谢谢大家
文件提供给客户端下载!希望大家提供一些例子!谢谢大家
解决方案 »
- 在编辑状态下,如何设定 dropdownlist 中的默认选定值为数据库对应值
- 求弹出式div进行编辑的功能实现源码
- 淘宝网中的“对比选中的宝贝”,怎么实现?
- 请问 vs.net 2002 编译好的项目能不能放在 .net 2003 的环境下运行?????
- ASP.NET 网站与discuz NT论坛注册,登录,注销整合
- 高分求一个上传大文件的web控件
- 如何实现一次性统计8个表中的数据[包括打印]
- vs2005里面可以开发.net1.1的程序吗?
- 高分求教:怎样向包括int, DateTime等非string参数的函数传递空值?
- ASP.NET怎麼去掉頁面的緩存內容!
- 异常处理:当连接不要上数据库时,如何处理?
- 请教!如何使用ASP.Net遍历sqlServer2000中的表
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
DataGrid1.DataSource =Panpipe.Common.TestDataBase.Instance.TestTable;
DataGrid1.DataBind();
}
}
public static void ToExcel(System.Web.UI.Control ctl,string FileName)
{
HttpContext.Current.Response.Charset ="UTF-8";
HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType ="application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+""+FileName+".xls");
ctl.Page.EnableViewState =false;
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();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
ToExcel(DataGrid1,"excel1");
}
http://blog.csdn.net/ChengKing/archive/2005/11/29/539514.aspx