(转)Excel导出及数据格式化处理
原文地址:http://www.cnblogs.com/cnaspnet/archive/2008/05/24/1206263.html
public void ToExcel(System.Web.UI.Control ctl, string FileName) {
        { HttpContext.Current.Response.Charset = "UTF-8";
            HttpContext.Current.Response.Charset = "UTF-8"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default; HttpContext.Current.Response.ContentType = "application/ms-excel";
            HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName + ".xls");
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName + ".xls"); ctl.Page.EnableViewState = false;
            ctl.Page.EnableViewState = false; System.IO.StringWriter tw = new System.IO.StringWriter();
            System.IO.StringWriter tw = new System.IO.StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw);
            HtmlTextWriter hw = new HtmlTextWriter(tw); ctl.RenderControl(hw);
            ctl.RenderControl(hw); HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.Write(tw.ToString()); HttpContext.Current.Response.End();
            HttpContext.Current.Response.End(); }
        } public override void VerifyRenderingInServerForm(Control control)
        public override void VerifyRenderingInServerForm(Control control) {
        { //base.VerifyRenderingInServerForm(control);
            //base.VerifyRenderingInServerForm(control); }
        } protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e) {
        { if (e.Row.RowType == DataControlRowType.DataRow)
            if (e.Row.RowType == DataControlRowType.DataRow) {
            { //e.Row.Cells[0].Attributes.Add("style", "vnd.ms-excel.numberformat:@");//这里是将要导出到execl里的第一列格式化为字符类型。
                //e.Row.Cells[0].Attributes.Add("style", "vnd.ms-excel.numberformat:@");//这里是将要导出到execl里的第一列格式化为字符类型。 //e.Row.Cells[3].Attributes.Add("style", "vnd.ms-excel.numberformat:¥#,###.00");//这里是格式化为货币类型。
                //e.Row.Cells[3].Attributes.Add("style", "vnd.ms-excel.numberformat:¥#,###.00");//这里是格式化为货币类型。 e.Row.Cells[4].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
                e.Row.Cells[4].Attributes.Add("style", "vnd.ms-excel.numberformat:@"); //1) 文本:vnd.ms-excel.numberformat:@
                //1) 文本:vnd.ms-excel.numberformat:@ //2) 日期:vnd.ms-excel.numberformat:yyyy/mm/dd
                //2) 日期:vnd.ms-excel.numberformat:yyyy/mm/dd //3) 数字:vnd.ms-excel.numberformat:#,##0.00
                //3) 数字:vnd.ms-excel.numberformat:#,##0.00 //4) 货币:vnd.ms-excel.numberformat:¥#,##0.00
                //4) 货币:vnd.ms-excel.numberformat:¥#,##0.00 //5) 百分比:vnd.ms-excel.numberformat: #0.00%
                //5) 百分比:vnd.ms-excel.numberformat: #0.00% }
            } }
        }
(转)Excel导出及数据格式化处理的更多相关文章
- Excel导出数据库数据
		package com.hxkr.util; import java.io.FileOutputStream; import java.util.ArrayList; import java.util ... 
- vue如何使用excel导出后台数据
		let params = { // 请求参数 要下载Excel的id 'id':this.excelId }; //导入的接口名 api_excel_exportExcel().then(res =& ... 
- excel 导出长数据 变成科学计数 解决办法
		加 “\t” 
- 一个通用的DataGridView导出Excel扩展方法(支持列数据格式化)
		假如数据库表中某个字段存放的值“1”和“0”分别代表“是”和“否”,要在DataGridView中显示“是”和“否”,一般用两种方法,一种是在sql中直接判断获取,另一种是在DataGridView的 ... 
- 利用Aspose.Cells完成easyUI中DataGrid数据的Excel导出功能
		我准备在项目中实现该功能之前,google发现大部分代码都是利用一般处理程序HttpHandler实现的服务器端数据的Excel导出,但是这样存在的问题是ashx读取的数据一般都是数据库中视图的数据, ... 
- vue2 Excel导出数据 js-xlsx的使用
		vue2 Excel导出数据 js-xlsx的使用 https://www.jianshu.com/p/ea115a8e9107 小世界最温暖 关注 2018.11.19 16:08 字数 280 阅 ... 
- SpringBoot图文教程10—模板导出|百万数据Excel导出|图片导出「easypoi」
		有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文教程系列文章目录 SpringBoot图文教程1「概念+ ... 
- thinkphp导入导出excel表单数据
		在PHP项目经常要导入导出Excel表单. 先去下载PHPExcel类库文件,放到相应位置. 我在thinkphp框架中的位置为ThinkPHP/Library/Org/Util/ 导入 在页面上传e ... 
- Java利用POI导入导出Excel中的数据
		首先谈一下今天发生的一件开心的事,本着一颗android的心我被分配到了PB组,身在曹营心在汉啊!好吧,今天要记录和分享的是Java利用POI导入导出Excel中的数据.下面POI包的下载地 ... 
随机推荐
- powerdesigner导出SQL时大写转换
			打开物理模型,点击菜单“Tools->Execute Commands -> Edit/Run Script...",或者快捷键(Ctrl+Shift+X)执行下面vbscrip ... 
- Linux文件类型与扩展名
			Linux文件类型和Linux文件的文件名所代表的意义是两个不同的概念.我们通过一般应用程序而创建的比如file.txt.file.tar.gz ,这些文件虽然要用不同的程序来打开,但放在Linux文 ... 
- dev combobox edit 怎么设置让选项清空
			dev combobox edit 怎么设置让选项清空 功能需求: 点击combobox edit1的选项A 使得 combobox edit2出现选项a: 然后再点击combobox edit1的选 ... 
- 从修复 testerhome(rubychina)网站的一个 bug 学习 ruby&rails on ruby
			前言 testerhome: http://testerhome.com/topics/1480 对于一个差点脱离前沿技术人,想要学习ruby,就意味着要放弃熟悉的操作系统windows,熟悉的ide ... 
- 【原创】LoadRunner Java Vuser开发环境配置指南
			1 编写目的 本文主要介绍Java运行环境的配置,同时通过编写HelloWorld程序,讲解在LoadRunner下如何开发简单的Java Vuser脚本.关于Java语言的深入学习,大家可以参考其他 ... 
- linux 已有目录挂载磁盘
			1.查看当前硬盘使用状况: [root@gluster_node1 ~]# df -h Filesystem Size Used Avail Use% Mounted on / ... 
- [POJ2348]Euclid's Game
			Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8313 Accepted: 3374 Description Two p ... 
- Java笔记(十三)……面向对象III继承(inheritance)
			继承概述 继承概述 多个类中存在相同属性和行为时,将这些内容抽取到单独一个类中,那么多个类无需再定义这些属性和行为,只要继那个类即可. 多个类可以称为子类,单独这个类称为父类或者超类. 子类可以直接访 ... 
- unexpected error ConnectionError object has no attribute
			unexpected error ConnectionError object has no attribute 
- Java读取文件夹大小的6种方法及代码
			(一)单线程递归方式 package com.taobao.test; import java.io.File; public class TotalFileSizeSequential { publ ... 
