一、输出到excel

函数:

    protected void InputFileTheme(object[] Header,object [] DataFileds,string sql,string filename)
        {
            SqlDBHandler dbHandler=this.getDBHandler();
            string filterStr=",";
            string strTemp;

            Hashtable hashTable=new Hashtable();
            //hashTable.Add("laguage","513");//正文语种
            /*hashTable.Add("themetype3","504");//参考地图地域类别
            hashTable.Add("themetype4","505");//参考地图形式类别
            hashTable.Add("themetype5","508");//基础教材性质类别
            hashTable.Add("themetype6","506");//基础教材学科类别
            hashTable.Add("themetype8","519");//教辅性质
            //基础教材版别
            hashTable.Add("usesegment","509");//基础教材使用学段
            hashTable.Add("useterm","510");//基础教材使用学期
            hashTable.Add("managemode","511");//编务管理类别
            hashTable.Add("electype","608");//电子出版物类型 (dictid=608)

            hashTable.Add("bindmode","516");//装帧形式
            hashTable.Add("papersize","605");//纸张尺寸
            hashTable.Add("isfund","517");//出版基金类别
            */
            if(sql.Trim().Equals(""))
                return;
            if(DataFileds==null)
                return;
            if(filename.Equals(""))
                filename="default";
            int len;
            string strInput;

            StringWriter sw=new StringWriter();

            //输出表头
            if(Header!=null)
            {
                strInput="";
                ;len<Header.Length;len++)
                {
                    if(Header[len]!=null)
                    {
                        if(strInput.Equals(""))
                            strInput=Header[len].ToString();
                        else
                            strInput+=filterStr+Header[len].ToString();
                    }
                }//for(len=0;len<Header.Length;len++)
                strInput="序号"+filterStr+strInput;
                sw.WriteLine(strInput);
            }//if(Header!=null)

            DataTable dt=dbHandler.ExecuteDataTable(sql);
            dt=CncBw.Db.ThemeInfoSet.ThemeInfoDictTransfer(dt);
            ;
            foreach(DataRow dr in dt.Rows)
            {
                strInput="";
                row+=;
                ;len<DataFileds.Length;len++)
                {
                    )
                    {

                        //输入字段,输出数据
                        if(dr[DataFileds[len].ToString()]!=null)
                        {
                            strTemp=dr[DataFileds[len].ToString()].ToString().Trim();
                            strTemp=strTemp.Replace(",",",");
                            strInput=strTemp;
                        }
                        else
                        {
                            strInput="null";
                        }//if(dr[DataFileds[len]]!=null)
                    }
                    else
                    {
                        if(dr[DataFileds[len].ToString()]!=null)
                        {
                            strTemp=dr[DataFileds[len].ToString()].ToString().Trim();
                            strTemp=strTemp.Replace(",",",");
                            strTemp = strTemp.Replace("\r\n", " ");

                            strInput+=filterStr+strTemp;
                        }
                        else
                            strInput+=filterStr+"null";
                    }//if(len==0)

                }//for(len=0;len<DataFileds.Length;len++)
                strInput=row.ToString()+filterStr+strInput;
                sw.WriteLine(strInput);
            }//foreach(DataRow dr in dt.Rows)

            sw.Close();
            Response.AddHeader("Content-Disposition", "attachment;filename="+filename+".csv");
            Response.ContentType = "application/ms-excel";
            Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
            //Response.ContentEncoding=System.Text.Encoding.GetEncoding("unicode");
            Response.Write(sw);
            Response.End();
            dbHandler.Close();
        }

二、调用

this.InputFileTheme(header,dataFileds,strSql,"bookinfo");

bianwu 哈希表输出到 excel的更多相关文章

  1. arcgis api for javascript 学习(三) 调用发布地图信息,并将地图属性信息输出到Excel表中

    吐血推荐:网上搜了很久关于webgis地图属性表输出到Excel表,并没能找到相关有价值的信息,在小白面前,这就是一脸懵x啊!网上要么是关于前端如何在页面上直接导出excel,和webgis半毛钱关系 ...

  2. 【哈希表】CodeVs1230元素查找

    一.写在前面 哈希表(Hash Table),又称散列表,是一种可以快速处理插入和查询操作的数据结构.哈希表体现着函数映射的思想,它将数据与其存储位置通过某种函数联系起来,其在查询时的高效性也体现在这 ...

  3. openssl lhash 数据结构哈希表

    哈希表是一种数据结构,通过在记录的存储位置和它的关键字之间建立确定的对应关系,来快速查询表中的数据: openssl lhash.h 为我们提供了哈希表OPENSSL_LHASH 的相关接口,我们可以 ...

  4. hdu acm 1425 sort(哈希表思想)

    sort Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. noip模拟赛 好元素 哈希表的第一题

    这是一道关于 题2好元素 2s [问题描述] 小A一直认为,如果在一个由N个整数组成的数列{An}中,存在以下情况: Am+An+Ap = Ai (1 <= m, n, p < i < ...

  6. [转]net中哈希表的使用 Hashtable

    本文转自:http://www.cnblogs.com/gsk99/archive/2011/08/28/2155988.html 以下是PetShop中DBHelper中的使用过程: //创建哈希表 ...

  7. Snowflake Snow Snowflakes(哈希表的应用)

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 27312   Accep ...

  8. 索引器、哈希表Hashtabl、字典Dictionary(转)

    一.索引器 索引器类似于属性,不同之处在于它们的get访问器采用参数.要声明类或结构上的索引器,使用this关键字. 示例:   索引器示例代码 /// <summary> /// 存储星 ...

  9. c# 哈希表跟函数

    一.哈希表集合 先进后出,一个一个赋值,但只能一起取值. 1.哈希表的建立.赋值以及读取. 2.利用枚举类型打印出集合中的Key值和Value值. 二.函数 函数:能够独立完成某项功能的模块. 函数四 ...

随机推荐

  1. 使用Redis来实现LBS的应用

    原文地址 微信.陌陌 架构方案分析 近两年.手机应用,莫过于微信.陌陌之类最受欢迎:但实现原理,分享文章甚少. 故,提出两种方案,供分享:不对之处,敬请留言学习. 目标 查找附近的某某某,由近到远返回 ...

  2. Process启动.exe,当.exe内部抛出异常时,总会弹出一个错误提示框,阻止Process进入结束

    public class TaskProcess { [DllImport("kernel32.dll", SetLastError = true)] public static ...

  3. Swift动画编程指南-01 简介

    大家好,我是老镇,这段时间家里和工作上发生了很多的事情,所以很长一段时间都没有出来搞什么小动作了.在接下来的一段时间内我会制作一些列关于使用Swift进行动画编程的视频,希望和大家胃口. 在iOS的世 ...

  4. Leetcode: Trapping Rain Water II

    Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevati ...

  5. codeforces343A A. Rational Resistance

    http://http://codeforces.com/problemset/problem/343/A A. Rational Resistance time limit per test 1 s ...

  6. csuoj 1111: 三家人

    acm.csu.edu.cn/OnlineJudge/problem.php?id=1111 1111: 三家人 Time Limit: 1 Sec  Memory Limit: 128 MBSubm ...

  7. IMapDocument interface

      Provides access to members that control the reading and writing of map document files.(提供访问的成员,控制读 ...

  8. 【py分析】使用SGMLParser分析淘宝html

    SGMLParser Python 默认自带 HTMLParser 以及 SGMLParser 等等解析器,前者实在是太难用了,我就用 SGMLParser 写了一个示例程序: import urll ...

  9. Mysql 的存储引擎,myisam和innodb的区别

    MyISAM 是非事务的存储引擎,innodb是支持事务的存储引擎. innodb的引擎比较适合于插入和更新操作比较多的应用,而MyISAM 则适合用于频繁查询的应用 . MyISAM --表锁,in ...

  10. php里session的用法

    PHP中的session默认情况下是使用客户端的Cookie.当客户端的Cookie被禁用时,会自动通过Query_String来传递. Php处理会话的函数一共有11个,我们详细介绍一下将要用到几个 ...