[Excel] C#ExportExcel帮助类 (转载)
主要功能如下
1.将整个网页导出来Excel
2.将GridView数据导出Excel
最新的ExportExcel操作类
看下面代码吧
/// <summary>
/// 类说明:ExportExcel
/// 编 码 人:苏飞
/// 联系方式:361983679
/// 更新网站:[url=http://www.sufeinet.com/thread-655-1-1.html]http://www.sufeinet.com/thread-655-1-1.html[/url]
/// </summary>
using System;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Web.UI.WebControls; namespace DotNet.Utilities
{
public class ExportExcel
{
/// <summary>
/// 将整个网页导出来Excel
/// </summary>
/// <param name="strContent"></param>
/// <param name="FileName"></param>
protected void ExportData(string strContent, string FileName)
{
FileName = FileName + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "gb2312";
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
//this.Page.EnableViewState = false;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ".xls");
// 把文件流发送到客户端
HttpContext.Current.Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">");
HttpContext.Current.Response.Write(strContent); HttpContext.Current.Response.Write("</body></html>");
// 停止页面的执行
//Response.End();
} /// <summary>
/// 将GridView数据导出Excel
/// </summary>
/// <param name="obj"></param>
public void ExportData(GridView obj)
{
try
{
string style = "";
if (obj.Rows.Count > )
{
style = @"<style> .text { mso-number-format:\@; } </script> ";
}
else
{
style = "no data.";
} HttpContext.Current.Response.ClearContent();
DateTime dt = DateTime.Now;
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString();
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=ExportData" + filename + ".xls");
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
obj.RenderControl(htw);
HttpContext.Current.Response.Write(style);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
catch
{ }
}
}
}
[Excel] C#ExportExcel帮助类 (转载)的更多相关文章
- [Excel] C# ExcelHelper操作类 (转载)
点击下载 ExcelHelper.rar 主要功能如下1.导出Excel文件,自动返回可下载的文件流 2.导出Excel文件,转换为可读模式3.导出Excel文件,并自定义文件名4.将数据导出至Exc ...
- Workbook导出excel封装的工具类
在实际中导出excel非常常见,于是自己封装了一个导出数据到excel的工具类,先附上代码,最后会写出实例和解释.支持03和07两个版本的 excel. HSSF导出的是xls的excel,XSSF导 ...
- Excel导入导出帮助类
/// <summary> /// Excel导入导出帮助类 /// 记得引入 NPOI /// 下载地址 http://npoi.codeplex.com/rele ...
- C#导出数据到Excel通用的方法类
导出数据到Excel通用的方法类,请应对需求自行修改. 资源下载列表 using System.Data; using System.IO; namespace IM.Common.Tools { p ...
- 一个基于POI的通用excel导入导出工具类的简单实现及使用方法
前言: 最近PM来了一个需求,简单来说就是在录入数据时一条一条插入到系统显得非常麻烦,让我实现一个直接通过excel导入的方法一次性录入所有数据.网上关于excel导入导出的例子很多,但大多相互借鉴. ...
- Delphi Excel导入 的通用程序转载
Delphi Excel导入 的通用程序 (-- ::)转载▼ 标签: it 分类: Delphi相关 步骤: 连excel(自己知道其格式,最好是没个字段在数据一一对应) 读excel数据,填入到数 ...
- Excel解析easyexcel工具类
Excel解析easyexcel工具类 easyexcel解决POI解析Excel出现OOM <!-- https://mvnrepository.com/artifact/com.alibab ...
- Java基础学习总结(49)——Excel导入导出工具类
在项目的pom文件中引入 <dependency> <groupId>net.sourceforge.jexcelapi</groupId> <artifac ...
- [Excel] C#GridViewExport帮助类,美化导出 (转载)
主要功能如下1.将整GridView的数据导出到Excel中关增加一个效果线做美化最新的GridViewExport操作类看下面代码吧 /// <summary> /// 类说明:Grid ...
随机推荐
- C#面向对象——成员变量及封装
namespace 面向对象5_22 { class Animal { private string _Type; public string Type { get { return _Type; } ...
- IIS7部署ASP.NET MVC4程序报错解决
今天安装了windows7 开发web项目需要安装IIS,当安装完以后,web程序已经映射到了本地IIS上,运行出现如下错误提示 处理程序“PageHandlerFactory-Integrated” ...
- -_-#【JS】element.click()
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Color the ball----HDOJ1556
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- bzoj 2761 [JLOI2011]不重复数字(哈希表)
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3210 Solved: 1186[Submit][Sta ...
- extjs的button控件fireEvent('click')无效问题
extjs的button控件fireEvent('click')无效问题 2012-06-06 16:39 891人阅读 评论(0) 收藏 举报 extjsbuttoncallbackfunction ...
- 忘记gitlab的root密码
甚至也忘记了邮箱,或许是默认邮箱无法使用. 需要在服务器上面直接修改数据: gitlab-rails console production user = User.where().first user ...
- RHEL7下安装使用TensorFlow和kcws
0.安装依赖包 #用pip安装python科学计算库numpy,sklearn,scipysu - wget http://dl.fedoraproject.org/pub/epel/7/x86_64 ...
- phonegap与微信开放平台接口整合
在开发phonegap应用的过程中有个需求需要将应用的消息推送到微信上.于是我自己写了一个微信的phonegap插件,并成功整合进了应用. 插件地址:https://github.com/ajccom ...
- 利用Dnspod api批量更新添加DNS解析【python脚本】 - 推酷
利用Dnspod api批量更新添加DNS解析[python脚本] - 推酷 undefined