//CC_AutoId, CC_LoginId, CC_LoginPassword, CC_UserName, CC_ErrorTimes, CC_LockDateTime, CC_TestInt
            string sqlStr = "select * from T_Seats";
            using (SqlDataReader reader = Alian_SQL_Helper.SqlHelper .ExecuteReader(sqlStr, CommandType .Text))
            {
                if (reader.HasRows)
                {
                    //获得列的索引
                    int autoIdindex = reader.GetOrdinal("CC_AutoId" );
                    int loginIdIndex = reader.GetOrdinal("CC_LoginId" );
                    int loginPasswordIndex = reader.GetOrdinal("CC_LoginPassword" );
                    int userNameIndex = reader.GetOrdinal("CC_UserName" );
                    int errorTimesIndex = reader.GetOrdinal("CC_ErrorTimes" );
                    int lockDateTimeIndex = reader.GetOrdinal("CC_LockDateTime" );
                    int testIntIndex = reader.GetOrdinal("CC_TestInt" );
                    using (Workbook wk = new HSSFWorkbook ())
                    {
                        //创建工作表
                        using (Sheet sheet = wk.CreateSheet("24K" ))
                        {
                            int rowIndex = 0 ;
 
                            while (reader.Read())
                            {
                                 //读取数据
                                Seats seats = new Seats();
                                seats.CC_AutoId = reader.GetInt32(autoIdindex);
                                seats.CC_LoginId = reader.GetString(loginIdIndex);
                                seats.CC_LoginPassword = reader.GetString(loginPasswordIndex);
                                seats.CC_UserName = reader.GetString(userNameIndex);
                                seats.CC_ErrorTimes = reader.GetInt32(errorTimesIndex);
 
                                seats.CC_LockDateTime = reader.IsDBNull(lockDateTimeIndex) ? null : (DateTime?)reader.GetDateTime (lockDateTimeIndex );
                                seats.CC_TestInt = reader.IsDBNull(testIntIndex) ? null : (int?)reader.GetInt32 (testIntIndex );
                                Row row = sheet.CreateRow(rowIndex);
                                row.CreateCell(0) .SetCellValue( seats.CC_AutoId);
 
                                row.CreateCell(1) .SetCellValue( seats.CC_LoginId);
 
                                row.CreateCell(2) .SetCellValue( seats.CC_LoginPassword);
 
                                row.CreateCell(3) .SetCellValue( seats.CC_UserName);
 
                                row.CreateCell(4) .SetCellValue( seats.CC_ErrorTimes);
 
                                Cell cell1 = row.CreateCell (5);
                                if (seats.CC_LockDateTime == null)
                                {
                                    cell1.SetCellType(CellType .BLANK);
                                }
                                else
                                {
                                      //添加相应的时间样式
                                    cell1.SetCellValue((DateTime )seats.CC_LockDateTime );
                                    CellStyle cellStyle = wk.CreateCellStyle();
                                    cellStyle.DataFormat = HSSFDataFormat .GetBuiltinFormat("m/d/yy h:mm" );
                                    cell1.CellStyle = cellStyle ;
                                }
 
 
                                Cell cellTestInt = row.CreateCell(6);
                                //对数字类型进行判断 让他可以在表格中参与计算
                                if (seats.CC_TestInt == null)
                                {
                                    cellTestInt.SetCellType(CellType .BLANK);
                                }
                                else
                                {
                                    cellTestInt.SetCellValue((int)seats.CC_TestInt );
                                }
                                rowIndex++;
                            }
                               //保存
                            using (FileStream fileStreamWrite = File.OpenWrite( "24K.xls"))
                            {
                                wk.Write(fileStreamWrite );
                            }
                        }
                    }
 
                }
            }

从数据库中读取数据并写入到Excle电子表格之2的更多相关文章

  1. Jmeter从数据库中读取数据

    Jmeter从数据库中读取数据 1.测试计划中添加Mysql Jar包 2.添加线程组 3.添加 jdbc connection configuration 4.添加JDBC Request,从数据库 ...

  2. JDBC Java 程序从 MySQL 数据库中读取数据,并备份到 xml 文档中

    MySQL 版本:Server version: 5.7.17-log MySQL Community Server (GPL) 相关内容:JDBC Java 程序从 MySQL 数据库中读取数据,并 ...

  3. 怎样在C#中从数据库中读取数据(数据读取器)

    实现在C#中通过语句,查询数据库中的数据 SqlConnection con = null; //创建SqlConnection 的对象 try    //try里面放可能出现错误的代码        ...

  4. 纯静态界面中(html)中通过js调用dll中的方法从数据库中读取数据

    最近接到一个离职员工的任务,一个搭好框架的ERP系统,看了两天,说一下看到的东西,整个项目目录中我没发现一个.aspx后缀的文件,全是静态HTML文件,之后发现他用的jquery简直看的头疼,不过大概 ...

  5. Kafka消费者 从Kafka中读取数据并写入文件

    Kafka消费者 从Kafka中读取数据 最近有需求要从kafak上消费读取实时数据,并将数据中的key输出到文件中,用于发布端的原始点进行比对,以此来确定是否传输过程中有遗漏数据. 不废话,直接上代 ...

  6. Java从.CSV文件中读取数据和写入

    .CSV文件是以逗号分割的数据仓储,读取数据时从每一行中读取一条数据元祖,也就是一条数据,再用字符分割的方式获取表中的每一个数据项. import java.io.BufferedReader;    ...

  7. JDBC Java 程序从 MySQL 数据库中读取数据,并封装到 Javabean 对象中

    MySQL 版本:Server version: 5.7.17-log MySQL Community Server (GPL) 相关内容:JDBC Java 连接 MySQL 数据库 用于测试的 M ...

  8. struts2中从数据库中读取数据,并在JSP页面中遍历保存有JavaBean对象的List对象

    0x1:前言 前面搭建struts就不说了,大家都能成功完毕. 0x2:Model 这里我们须要一个Model类来接收 <span style="font-size:10px;font ...

  9. CSV文件导入到数据库中读取数据详解(接着上个帖子)

    一.controller层 二.SERVICE层 @Overridepublic Result importJinjiangAssessResult(MultipartFile file) throw ...

  10. HighCharts从数据库中读取数据

    1.index.js router.get('/', function(req, res, next) { res.render('index', { title: 'Express' }); }); ...

随机推荐

  1. PHP开发者交流群

    PHP开发者交流群 欢迎大家加入学习讨论 QQ群(493834732)

  2. ts、typescript、enum、枚举、ts 获取枚举对应的类型、获取 enum 的 key 和 value

    ts.typescript.enum.枚举.ts 获取枚举对应的类型 // 假设我一个枚举 enum ENUM_TYPE { ALL = 'all', SOME = 'some', LITTLE = ...

  3. VUE的路由懒加载及组件懒加载

    一,为什么要使用路由懒加载 为给客户更好的客户体验,首屏组件加载速度更快一些,解决白屏问题 二,懒加载简单来说就是延迟加载或按需加载,即在需要的时候的时候进行加载 三,常用的懒加载方式有两种:即使用v ...

  4. [Pytorch框架] 4.2.1 使用Visdom在 PyTorch 中进行可视化

    文章目录 4.2.1 使用Visdom在 PyTorch 中进行可视化 安装 坑 基本概念 Environments Panes VIEW 可视化接口 使用 绘制简单的图形 更新损失函数 import ...

  5. #PowerBI 1分钟学会,利用format函数,自定义格式显示

    PowerBI是一款强大的数据分析和可视化工具,它可以帮助我们快速地创建各种报表和仪表盘,展示数据的洞察和价值. 在PowerBI中,有许多内置的函数可以帮助我们处理和转换数据,其中一个常用的函数就是 ...

  6. 2022-12-10:给你一个由小写字母组成的字符串 s ,和一个整数 k 如果满足下述条件,则可以将字符串 t 视作是 理想字符串 : t 是字符串 s 的一个子序列。 t 中每两个 相邻 字母在字

    2022-12-10:给你一个由小写字母组成的字符串 s ,和一个整数 k 如果满足下述条件,则可以将字符串 t 视作是 理想字符串 : t 是字符串 s 的一个子序列. t 中每两个 相邻 字母在字 ...

  7. 2020-10-02:golang如何写一个插件?

    福哥答案2020-10-02:#福大大架构师每日一题#简单回答:buildmode=plugin plugin.Openp.Lookup [中级回答:](https://www.zhihu.com/q ...

  8. 2021-09-18:给定一个只包括 ‘(‘,‘)‘,‘{‘,‘}‘,‘[‘,‘]‘ 的字符串 s ,判断字符串是否有效。有效字符串需满足:左括号必须用相同类型的右括号闭合。左括号必须以正确的顺序闭合

    2021-09-18:给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效.有效字符串需满足:左括号必须用相同类型的右括号闭合.左括号必须以正确的顺序闭合 ...

  9. Python-查询所有python版本

    C:\Users\liujun>where pythonD:\Python\Python310\python.exeD:\Python\Python38\python.exeC:\Users\l ...

  10. ModuleNotFoundError: No module named 'flask_login'

    ModuleNotFoundError: No module named 'flask_login' 解决: pip install  flask_login