目录
前言
报表分为Excel ,word ,pdf 不过Excel更加的常用
一、Excel的两种形式
Excel分为两种形式一种Excel2003一种Excel2007两种
03版的是用二进制流的方式构造 文件后缀 .xls
07版则是xml文件构造 文件后缀 .xlsx
03版数据存储容量小
07版数据存储容量大占用空间小效率更高
二、POI概述
POI比较主流的Excel报表操作管理工具
一般运用于导入导出操作
上传数据(导入):用于上传Excel报表数据到数据库中
生成报表(导出):把数据库的数据导出并写入报表中 word , excel , pdf 都可用来存储数据
三、POI结构说明
HSSF提供读写Microsoft Excel XLS格式档案的功能。03
XSSF提供读写Microsoft Excel OOXML XLSX格式档案的功能。07
HWPF提供读写Microsoft Word DOC格式档案的功能。word
HSLF提供读写Microsoft PowerPoint格式档案的功能。PPT
HDGF 提供读写Microsoft Visio格式档案的功能。
1.导出代码案例
1.要导入的jar包
如下(示例):
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>5.13.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
</dependencies>
2.后台controller代码
//ps :报表的第一行和第一格的下标索引都是从0开始
//创建工作薄
Workbook workbook = new XSSFWorkbook();
//设置表单
Sheet sheet = workbook.createSheet("test");
//设置行从第一行开始
Row row = sheet.createRow(0);
String[] s ={"编号","姓名","性别","年龄","时间","did"};
for (int i = 0; i < s.length; i++) {
//循环设置单元格
Cell cell = row.createCell(i);
//循环设置单元格里面的数据
cell.setCellValue(s[i]);
}
//调用方法提取从数据库所有数据
List<Emp> emp = empService.findEmp(new Emp());
for (int i = 0; i < emp.size(); i++) {
//循环提取每一个对象
Emp emp1 = emp.get(i);
//循环设置单元行
Row row1 = sheet.createRow(i + 1);
//设置每个单元格的信息
row1.createCell(0).setCellValue(emp1.getEid());
row1.createCell(1).setCellValue(emp1.getName());
row1.createCell(2).setCellValue(emp1.getSex());
row1.createCell(3).setCellValue(emp1.getAge());
//通过匿名内部类把时间类型转换成字符串
row1.createCell(4).setCellValue( new SimpleDateFormat("yyyy-MM-dd").format(emp1.getTime()));
row1.createCell(5).setCellValue(emp1.getDid());
}
//设置前端页面点击下载
response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode("员工列表.xlsx", "UTF-8"));
response.setHeader("Connection", "close");
response.setHeader("Content-Type", "application/octet-stream");
workbook.write(response.getOutputStream());
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。