先引用Microsoft Excel 9.0 Object Libraryusing Excel;
public void ToExcel(System.Web.UI.Control ctl)
{
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=Excel.xls");
HttpContext.Current.Response.Charset ="UTF-8";
HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType ="application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
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();
}
public void ToExcel(System.Web.UI.Control ctl)
{
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=Excel.xls");
HttpContext.Current.Response.Charset ="UTF-8";
HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType ="application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
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();
}
解决方案 »
- 请问连接MySql数据库
- 如何输写报文???
- socket 异步服务器,怎么把连接的客户端都显示出来???
- axPictureClip控件实现截图出现问题,仍然原来大小,如何解决?
- C#中父窗中,怎么确保每次只显示一个子窗口,怎么确定子窗口的显示位置
- 100分,来者有份,问题也很简单,快来啊
- 散100分在线等C#有关异步通信的问题,急!!~
- 2个线程同时做同一个操作,不影响主线程的其他操作
- 一个看似简单的问题(对象调用类的私有成员)
- Xceed.Wpf.AvalonDock 无法展开工具栏
- DataGrid如何使用double click事件,一点就到文本筐中了。
- c#有没有时间类型。怎样取得系统时间。
http://www.csdn.net/Develop/Read_Article.asp?Id=16482
你的方法有一个问题即001会变成1