asp.net导出EXCEL的功能代码
2008-07-11 08:53
701 查看
复制代码 代码如下:
//由gridviw导出为Excel
public static 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();
}
这是一段网上很多人使用的导出EXCEL代码,但使用过程中发现很多不足的地方,其不用引入其它控件。
缺点:
1、我采用ASPNETPAGER分页时只能导出第一页。
2、使用十分不灵活,对样式的控制,字段的控制不灵活。
使用中需要注意:
1、 <%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="Default.aspx.cs" Inherits="_Default"%>
加上这句。
2、在后台文件中加上:
public override void VerifyRenderingInServerForm(Control control)
{
}
3、需引入 using System.IO;
其它相关文章:
ASP.NET操作Excel备忘录
ASP.net连接Excel的代码
asp.net 读取并显示excel数据的实现代码
在Asp.net用C#建立动态Excel
asp.net 操作excel的实现代码
//由gridviw导出为Excel
public static 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();
}
这是一段网上很多人使用的导出EXCEL代码,但使用过程中发现很多不足的地方,其不用引入其它控件。
缺点:
1、我采用ASPNETPAGER分页时只能导出第一页。
2、使用十分不灵活,对样式的控制,字段的控制不灵活。
使用中需要注意:
1、 <%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="Default.aspx.cs" Inherits="_Default"%>
加上这句。
2、在后台文件中加上:
public override void VerifyRenderingInServerForm(Control control)
{
}
3、需引入 using System.IO;
其它相关文章:
ASP.NET操作Excel备忘录
ASP.net连接Excel的代码
asp.net 读取并显示excel数据的实现代码
在Asp.net用C#建立动态Excel
asp.net 操作excel的实现代码
您可能感兴趣的文章:
相关文章推荐
- asp.net导出EXCEL的功能代码
- asp.net导出excel-一行代码实现excel、xml、pdf、word、html、csv等7种格式文件导出功能而且美观-SNF快速开发平台
- C# ASP.net 将GridView中的数据导出到Excel中的代码
- asp.net Grid 导出Excel实现程序代码
- YbSoftwareFactory 代码生成插件【十】:ASP.NET WebApi MVC下审计、缓存和导出功能的实现
- asp.net Grid 导出Excel实现程序代码
- asp.net中Excel导入导出控件 2.0升级版本和1.0版本代码开源
- ASP.NET 中直接把gridview的视图内容导出到excel的关键代码
- ASP.NET 导出到Excel时保留换行的代码
- asp.net 导出Excel时,解决纯数字字符串变成类似这样的 2.00908E+18 形式的代码
- asp.net导出Excel完整代码,乱码解决方案
- 关于asp.net与winform导出excel的代码
- Asp.net 2.0 GridView数据导出Excel文件(示例代码下载)
- Asp.net 2.0 GridView数据导出Excel文件(示例代码下载)
- asp.net Linq把数据导出到Excel的代码
- asp.net导出excel较为简约的代码
- asp.net GridView导出到Excel代码
- asp.net Excel导出功能
- asp.net webform/mvc导出Excel通用代码