数据库查询的数据导出到xls表,集合数据导出到xls表
//实体类
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表的更多相关文章
- 利用Merge Into 更新表,集合数据到数据库中
使用Merge INTO 将表数据更新到数据库中 创建User-Defined Table Types 创建要更新的UserDetails表 创建更新存储过程 程序调用存储过程 查看结果
- kettle 表输入+流查询 与 数据库查询
他们的主要区别: •流查询步骤只能进行等值查询,数据库查询步骤可以进行非等值查询 •流查询在查询之前把数据都加载到内存里,数据库查询可以选择是否把数据加载到内存. •进行等值查询时,数据库查询步骤如果 ...
- JVM-class文件完全解析-属性表集合
属性表集合 在前面魔数,次版本号,主板本号,常量池入口,常量池,访问标志,类索引,父类索引,接口索引集合,字段表集合,方法表集合,那么接下来就是属性表集合了. 在class文件,字段表,方法表都可 ...
- iOS不得姐项目--推荐关注模块(一个控制器控制两个tableView),数据重复请求的问题,分页数据的加载,上拉下拉刷新(MJRefresh)
一.推荐关注模块(一个控制器控制两个tableView) -- 数据的显示 刚开始加载数据值得注意的有以下几点 导航控制器会自动调整scrollView的contentInset,最好是取消系统的设置 ...
- Oracle数据库--解决单张表中数据量巨大(大数据、数据量上百万级别,后查询,更新数据等耗时剧增)
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/QQ578473688/article/details/54561397 思路1:采用备份表 备份表中 ...
- MySQL数据库表的数据插入、修改、删除、查询操作及实例应用
一.MySQL数据库表的数据插入.修改.删除和查询 CREATE DATABASE db0504; USE db0504; CREATE TABLE student ( sno ) NOT NULL ...
- C# - VS2019 WinFrm应用程序连接Access数据库,并简单实现数据库表的数据查询、显示
序言 众所周知,Oracle数据库和MySQL数据库一般在大型项目中使用,在某些小型项目中Access数据库使用较为方便,今天记录一下VS2019 WinFrm应用程序连接Access数据库,并实现数 ...
- 【EXP】导出数据库dmp文件,只有几张表有数据,剩下的所有表只有表结构没有数据
导出一个dmp,指定的表中有数据,其他的表只有表结构, 有数据的表只有几张,分别是A,B,C三张表,剩下的表都没有数据 思路: 导出一个111.dmp,所有的表都只是表结构 将111.dmp导入到新创 ...
- T-SQL - query01_创建数据库|创建表|添加数据|简单查询
时间:2017-09-29 整理:byzqy 本篇以"梁山好汉花名册"为例,记录MS SQLServer T-SQL语句的使用,包含命令: 创建数据库 | 删除数据库 创建表 | ...
随机推荐
- JavaScript单独的模块中传递数据
首先我们来看看这张图,让我们来思考一下! 下买我给出我的完整思路代码 html代码: <!DOCTYPE html> <html lang="zh-CN"> ...
- WPF模拟键盘输入和删除
private void ButtonNumber_Click(object sender, RoutedEventArgs e) { Button btn = (Button)sender; str ...
- python接口自动化测试(四)-Cookie&Sessinon
掌握了前面几节的的内容,就可以做一些简单的http协议接口的请求发送了,但是这些还不够.HTTP协议是一个无状态的应用层协议,也就是说前后两次请求是没有任何关系的,那如果我们测试的接口之前有相互依赖关 ...
- CentOS7 安装FastDFS分布式文件系统
CentOS7 安装FastDFS分布式文件系统 最近要用到fastDFS,所以自己研究了一下,在搭建FastDFS的过程中遇到过很多的问题,为了能帮忙到以后搭建FastDFS的同学,少走弯路,与大家 ...
- [开源]开放域实体抽取泛用工具 NetCore2.1
开放域实体抽取泛用工具 https://github.com/magicdict/FDDC 更新时间 2018年7月16日 By 带着兔子去旅行 开发这个工具的起源是天池大数据竞赛,FDDC2018金 ...
- nrm管理npm源
npm源:npm install命令下载需要依赖包的服务器地址,默认是 npm ---- https://registry.npmjs.org/ 而国外的源速度太慢,所以我们一般都用国内的淘宝源tao ...
- 再看C# ThreadPool与Task的认识总结
工作线程与I/O线程 在ThreadPool中有这样一个方法: public static bool SetMaxThreads(int workerThreads, int completi ...
- TCP连接数过多问题
在一次生产上线后,发现使用的 8086 端口相关的 TCP 连接数竟然多大 6K+ ,有时候甚至会逼近 1w ,这个数量对于一个只是在内部使用的监控系统来说, 无论如何都是无法接受的, 于是开 ...
- VS2017打开VS2010项目报 “找不到*.xaml”错误
VS2017打开VS2010项目报 “找不到*.xaml”错误.详细如下: 未处理System.IO.IOExceptionMessage: “System.IO.IOException”类型的未经处 ...
- Centos7.4 安装Docker
一.安装docker yum install -y docker 二.启动docker服务 systemctl start docker 三.设置成开机启动docker服务 systemctl ena ...