原文地址: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.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();
            HtmlTextWriter hw = new HtmlTextWriter(tw);
            ctl.RenderControl(hw);
            HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.End();
        }
        public override void VerifyRenderingInServerForm(Control control)
        {
            //base.VerifyRenderingInServerForm(control);
        }
        protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //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[4].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
                //1) 文本:vnd.ms-excel.numberformat:@
                //2) 日期:vnd.ms-excel.numberformat:yyyy/mm/dd
                //3) 数字:vnd.ms-excel.numberformat:#,##0.00
                //4) 货币:vnd.ms-excel.numberformat:¥#,##0.00
                //5) 百分比:vnd.ms-excel.numberformat: #0.00%
            }
        }

(转)Excel导出及数据格式化处理的更多相关文章

  1. Excel导出数据库数据

    package com.hxkr.util; import java.io.FileOutputStream; import java.util.ArrayList; import java.util ...

  2. vue如何使用excel导出后台数据

    let params = { // 请求参数 要下载Excel的id 'id':this.excelId }; //导入的接口名 api_excel_exportExcel().then(res =& ...

  3. excel 导出长数据 变成科学计数 解决办法

    加 “\t”

  4. 一个通用的DataGridView导出Excel扩展方法(支持列数据格式化)

    假如数据库表中某个字段存放的值“1”和“0”分别代表“是”和“否”,要在DataGridView中显示“是”和“否”,一般用两种方法,一种是在sql中直接判断获取,另一种是在DataGridView的 ...

  5. 利用Aspose.Cells完成easyUI中DataGrid数据的Excel导出功能

    我准备在项目中实现该功能之前,google发现大部分代码都是利用一般处理程序HttpHandler实现的服务器端数据的Excel导出,但是这样存在的问题是ashx读取的数据一般都是数据库中视图的数据, ...

  6. vue2 Excel导出数据 js-xlsx的使用

    vue2 Excel导出数据 js-xlsx的使用 https://www.jianshu.com/p/ea115a8e9107 小世界最温暖 关注 2018.11.19 16:08 字数 280 阅 ...

  7. SpringBoot图文教程10—模板导出|百万数据Excel导出|图片导出「easypoi」

    有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文教程系列文章目录 SpringBoot图文教程1「概念+ ...

  8. thinkphp导入导出excel表单数据

    在PHP项目经常要导入导出Excel表单. 先去下载PHPExcel类库文件,放到相应位置. 我在thinkphp框架中的位置为ThinkPHP/Library/Org/Util/ 导入 在页面上传e ...

  9. Java利用POI导入导出Excel中的数据

         首先谈一下今天发生的一件开心的事,本着一颗android的心我被分配到了PB组,身在曹营心在汉啊!好吧,今天要记录和分享的是Java利用POI导入导出Excel中的数据.下面POI包的下载地 ...

随机推荐

  1. 从头开始编写一个Orchard网上商店模块(2) - 配置您的Orchard开发环境

    原文地址:http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-par ...

  2. HashSet的实现原理

    HashSet定义 public class HashSet<E> extends AbstractSet<E> implements Set<E>, Clonea ...

  3. POJ2236 Wireless Network 并查集

    水题 #include<cstdio> #include<cstring> #include<queue> #include<set> #include ...

  4. lightoj 1008

    水题,开根号判断大致范围,再找即可. #include<cstdio> #include<cmath> #include<cstdlib> using namesp ...

  5. object c小代码——日期篇

    1.判断两个日期是否是同一天,不要求小时,分钟要一样 用法 NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier: ...

  6. 改进的SMO算法

    S. S. Keerthi等人在Improvements to Platt's SMO Algorithm for SVM Classifier Design一文中提出了对SMO算法的改进,纵观SMO ...

  7. Esper系列(四)Output

    功能 控制Esper事件流计算结果的输入形式.时间点及频率: 格式 1  ";

  8. HW5.13

    public class Solution { public static void main(String[] args) { System.out.printf("%s\t%s\n&qu ...

  9. HDOJ-ACM1013(JAVA)

    这道题也很简单~主要是将输入转为字符串(存储大数,操作字符数组) 题意: 24 : 2 + 4 = 6  输出6 39 : 3 + 9 = 12 , 1 + 2 = 3 输出3 999: 9 + 9 ...

  10. 问题-Fastreport4 Memo打印时中文显示不全

    问题现象:在使用Fastreport4制作打印工具时,发现Memo显示中文老是显不不全. 问题原因:可能是因为字符编码的原因,希望高人指点. 问题处理:将属性font-charset设置为DEFAUL ...