//实体类
package com.outxls; public class Student { private Integer studentId;
private String studentName;
private String studentClass;
private String studentTel;
private String studentEmail;
public Integer getStudentId() {
return studentId;
}
public void setStudentId(Integer studentId) {
this.studentId = studentId;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getStudentClass() {
return studentClass;
}
public void setStudentClass(String studentClass) {
this.studentClass = studentClass;
}
public String getStudentTel() {
return studentTel;
}
public void setStudentTel(String studentTel) {
this.studentTel = studentTel;
}
public String getStudentEmail() {
return studentEmail;
}
public void setStudentEmail(String studentEmail) {
this.studentEmail = studentEmail;
}
public Student(Integer studentId, String studentName, String studentClass, String studentTel, String studentEmail) {
super();
this.studentId = studentId;
this.studentName = studentName;
this.studentClass = studentClass;
this.studentTel = studentTel;
this.studentEmail = studentEmail;
}
public Student() {
super(); }
@Override
public String toString() {
return "Student [studentId=" + studentId + ", studentName=" + studentName + ", studentClass=" + studentClass
+ ", studentTel=" + studentTel + ", studentEmail=" + studentEmail + "]";
} }
package com.outxls;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List; import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException; public class OutXlsUtil { public static void main(String[] args) {
//省去数据库查询代码 ,所有我自己直接写了一个集合代替查询到的数据
List<Student> stulist=new ArrayList<Student>();
Student stu=null;
for(int i=0;i<10;i++) {
stu=new Student();
stu.setStudentId(i+1);
stu.setStudentName("小明"+(i+1));
stu.setStudentClass("一班");
stu.setStudentTel("1337098123"+i);
stu.setStudentEmail("7632832"+i+"@qq.com");
stulist.add(stu);
} try {
outFilesUtil(stulist);
} catch (RowsExceededException e) { e.printStackTrace();
} catch (WriteException e) { e.printStackTrace();
} catch (IOException e) { e.printStackTrace();
}
} /**
*
* @param stulist 传一个集合
* @throws IOException
* @throws RowsExceededException
* @throws WriteException
*/
public static void outFilesUtil(List<Student> stulist) throws IOException, RowsExceededException, WriteException {
//用一个string 数组来设置xls表头
String[] title = { "序号", "姓名", "班级", "手机号码", "邮箱" };
// 创建一个输出的xls文件路径
String outPath = "C:\\Student.xls";
// 创建Excel 工作
WritableWorkbook wwb;
OutputStream os = null;
//输出流
os = new FileOutputStream(outPath);
wwb = Workbook.createWorkbook(os);
// 添加第一个工作表并设置第一个Sheet的名字
WritableSheet sheet = wwb.createSheet("学生信息", 0);
Label label;
for (int i = 0; i < title.length; i++) {
//设置表头
label = new Label(i, 0, title[i]);
sheet.addCell(label);
} // 这里是将查询的数据填写到xls表
for (int j = 0; j < stulist.size(); j++) {
//1 列
label = new Label(0, j + 1, stulist.get(j).getStudentId().toString());
sheet.addCell(label);
//2 列
label = new Label(1, j + 1, stulist.get(j).getStudentName());
sheet.addCell(label);
//3 列
label = new Label(2, j + 1, stulist.get(j).getStudentClass());
sheet.addCell(label);
//4 列
label = new Label(3, j + 1, stulist.get(j).getStudentTel());
sheet.addCell(label);
//5 列
label = new Label(4, j + 1, stulist.get(j).getStudentEmail());
sheet.addCell(label);
}
// 写入数据
wwb.write();
//刷新
os.flush();
// 关闭文件
wwb.close(); } }

 需要jxt.jar

数据库查询的数据导出到xls表,集合数据导出到xls表的更多相关文章

  1. 利用Merge Into 更新表,集合数据到数据库中

    使用Merge INTO 将表数据更新到数据库中 创建User-Defined Table Types   创建要更新的UserDetails表 创建更新存储过程 程序调用存储过程 查看结果

  2. kettle 表输入+流查询 与 数据库查询

    他们的主要区别: •流查询步骤只能进行等值查询,数据库查询步骤可以进行非等值查询 •流查询在查询之前把数据都加载到内存里,数据库查询可以选择是否把数据加载到内存. •进行等值查询时,数据库查询步骤如果 ...

  3. JVM-class文件完全解析-属性表集合

    属性表集合 在前面魔数,次版本号,主板本号,常量池入口,常量池,访问标志,类索引,父类索引,接口索引集合,字段表集合,方法表集合,那么接下来就是属性表集合了.   在class文件,字段表,方法表都可 ...

  4. iOS不得姐项目--推荐关注模块(一个控制器控制两个tableView),数据重复请求的问题,分页数据的加载,上拉下拉刷新(MJRefresh)

    一.推荐关注模块(一个控制器控制两个tableView) -- 数据的显示 刚开始加载数据值得注意的有以下几点 导航控制器会自动调整scrollView的contentInset,最好是取消系统的设置 ...

  5. Oracle数据库--解决单张表中数据量巨大(大数据、数据量上百万级别,后查询,更新数据等耗时剧增)

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/QQ578473688/article/details/54561397 思路1:采用备份表 备份表中 ...

  6. MySQL数据库表的数据插入、修改、删除、查询操作及实例应用

    一.MySQL数据库表的数据插入.修改.删除和查询 CREATE DATABASE db0504; USE db0504; CREATE TABLE student ( sno ) NOT NULL ...

  7. C# - VS2019 WinFrm应用程序连接Access数据库,并简单实现数据库表的数据查询、显示

    序言 众所周知,Oracle数据库和MySQL数据库一般在大型项目中使用,在某些小型项目中Access数据库使用较为方便,今天记录一下VS2019 WinFrm应用程序连接Access数据库,并实现数 ...

  8. 【EXP】导出数据库dmp文件,只有几张表有数据,剩下的所有表只有表结构没有数据

    导出一个dmp,指定的表中有数据,其他的表只有表结构, 有数据的表只有几张,分别是A,B,C三张表,剩下的表都没有数据 思路: 导出一个111.dmp,所有的表都只是表结构 将111.dmp导入到新创 ...

  9. T-SQL - query01_创建数据库|创建表|添加数据|简单查询

    时间:2017-09-29  整理:byzqy 本篇以"梁山好汉花名册"为例,记录MS SQLServer T-SQL语句的使用,包含命令: 创建数据库 | 删除数据库 创建表 | ...

随机推荐

  1. jsp执行过程图解

    转自:https://blog.csdn.net/y277an/article/details/76561451 一.jsp执行过程图解 用户访问jsp页面时,jsp的处理过程如下图所示: 二.预处理 ...

  2. SSE图像算法优化系列二十一:基于DCT变换图像去噪算法的进一步优化(100W像素30ms)。

    在优化IPOL网站中基于DCT(离散余弦变换)的图像去噪算法(附源代码) 一文中,我们曾经优化过基于DCT变换的图像去噪算法,在那文所提供的Demo中,处理一副1000*1000左右的灰度噪音图像耗时 ...

  3. 科技论文之Latex公式&amp;符号

    近期在写文章.有好多数学公式的命令都忘记了. 今天索性一起整理下. 1 能够在文章的作者上引用的符号 2  一些括号使用方法 3 一些高等数学的公式 4  交,并集 5  一些二项式 6 矩阵写法 7 ...

  4. WPF相关网址

    5.http://code.msdn.microsoft.com 4.仿真模拟多点触控:http://tinyurl.com/yawwhw2http://multitouchvista.codeple ...

  5. Apigee 简介与简单试用

     Apigee (国内访问需要***)是一家成立于2004年的API管理公司,于2016年9月被Google收购,作为Google云的服务之一.Apigee提供从API设计.开发.管理.门户.网关等 ...

  6. php生成毫秒时间戳的例子

    php时间函数time()生成当前时间的秒数,但是在一些情况下我们需要获取当前服务器时间和GMT(格林威治时间)1970年1月0时0分0秒的毫秒数,与Java中的currentTimeMilis()函 ...

  7. Unix时间转LInux时间

    private static long getTime() { long currentTimeMillis = System.currentTimeMillis(); long nanoTime = ...

  8. 刷机补丁包updater-script脚本

    1.单刷补丁包 新建META-INF文件夹,新建txt文件命名为:updater-script新建system文件夹,在里面新建app文件夹,把你要单刷的apk放进app文件夹在updater-scr ...

  9. oracle 优化or 更换in、exists、union all几个字眼

    oracle 优化or 更换in.exists.union几个字眼.测试没有问题! 根据实际情况选择相应的语句是.假设指数,or全表扫描,in 和not in 应慎用.否则会导致全表扫描.  sele ...

  10. C语言 sscanf用法详解

    /* sscanf用法详解 */ #include <stdio.h> /* sscanf头文件 */ #include <stdlib.h> #include <str ...