WEB 报表导入导出操作
/**
* 报表导出
* @param response
*/
@RequestMapping("/stuExcel")
@LogAnno(value="对学生数据进行了excel表格导出",grade="info")
public void stuExcel(HttpServletResponse response){
//查询所有学生信息
List<Student> list = stuService.selectAll();
//创建输出流
OutputStream fileOut = null;
try {
// 导出
// 重置输出流
response.reset();
// 设置导出Excel报表的导出形式
response.setContentType("application/vnd.ms-excel");
// 自定义响应文件名
String fileName = new String("学生信息表".getBytes("utf-8"),
"ISO-8859-1");
response.setHeader("Content-disposition", "attachment;filename="
+ fileName + ".xls");
fileOut = response.getOutputStream();
// 创建工作空间
Workbook wb = new HSSFWorkbook();
// 创建sheet
Sheet sheet = wb.createSheet("sheet1");
// 设置列宽
sheet.setColumnWidth(, );
sheet.setColumnWidth(, );
sheet.setColumnWidth(, );
sheet.setColumnWidth(, ); CreationHelper creationHelper = wb.getCreationHelper();
// 创建行 从 0 开始为第一行
Row row = sheet.createRow((short) );
row.setHeight((short) );// 目的是想把行高设置成25px
// 创建列 从0 开始为第一列
// 第一行的数据
row.createCell().setCellValue(
creationHelper.createRichTextString("学生编号")
);
row.createCell().setCellValue(
creationHelper.createRichTextString("学生姓名"));
// 设置String
row.createCell().setCellValue(
creationHelper.createRichTextString("就业单位"));
row.createCell().setCellValue(
creationHelper.createRichTextString("学生图片"));
row.createCell().setCellValue(
creationHelper.createRichTextString("学生薪资"));
row.createCell().setCellValue(
creationHelper.createRichTextString("入职时间"));
row.createCell().setCellValue(
creationHelper.createRichTextString("培训时间"));
row.createCell().setCellValue(
creationHelper.createRichTextString("是否是明星学员"));
row.createCell().setCellValue(
creationHelper.createRichTextString("学校"));
row.createCell().setCellValue(
creationHelper.createRichTextString("学历"));
row.createCell().setCellValue(
creationHelper.createRichTextString("工作地址"));
row.createCell().setCellValue(
creationHelper.createRichTextString("学生感言"));
row.createCell().setCellValue(
creationHelper.createRichTextString("状态"));
row.createCell().setCellValue(
creationHelper.createRichTextString("备注"));
row.createCell().setCellValue(
creationHelper.createRichTextString("作者")); int i=;
for (Student stu : list) { Row row1 = sheet.createRow((short) i);
row1.setHeight((short) );// 目的是想把行高设置成25px String uid=String.valueOf(stu.getStuId());
// 第二行的数据
row1.createCell().setCellValue(
creationHelper.createRichTextString(uid));
row1.createCell().setCellValue(
creationHelper.createRichTextString(stu.getStuName()));
// 设置String
row1.createCell().setCellValue(
creationHelper.createRichTextString(stu.getStuCompany()));
row1.createCell().setCellValue(
creationHelper.createRichTextString(stu.getStuPicture()));
row1.createCell().setCellValue(
creationHelper.createRichTextString(String.valueOf(stu.getStuSalary())));
row1.createCell().setCellValue(
creationHelper.createRichTextString(String.valueOf(new SimpleDateFormat("yyyy-MM-dd").format(stu.getStuEntrytime()))));
row1.createCell().setCellValue(
creationHelper.createRichTextString(String.valueOf(new SimpleDateFormat("yyyy-MM-dd").format(stu.getStuTrainingtime()))));
String isStart="否";
if(stu.getStuIsstar()!=null){
if(stu.getStuIsstar()==){
isStart="是";
}
}
row1.createCell().setCellValue(
creationHelper.createRichTextString(isStart));
row1.createCell().setCellValue(
creationHelper.createRichTextString(String.valueOf(stu.getStuSchool())));
row1.createCell().setCellValue(
creationHelper.createRichTextString(stu.getStuEducation()));
row1.createCell().setCellValue(
creationHelper.createRichTextString(stu.getStuWorkaddress()));
row1.createCell().setCellValue(
creationHelper.createRichTextString(stu.getStuRecollections()));
//1表示缉编中 2 待审核 3 待发布 4 取消发布 5 过期
String style="";
//判断状态
switch (stu.getStuState()) {
case :style="缉编中";break;
case :style="待审核";break;
case :style="待发布";break;
case :style="取消发布";break;
case :style="过期 ";break;
}
row1.createCell().setCellValue(
creationHelper.createRichTextString(style));
row1.createCell().setCellValue(
creationHelper.createRichTextString(stu.getStuNote()));
row1.createCell().setCellValue(
creationHelper.createRichTextString(stu.getStuWriter())); i++;
} wb.write(fileOut);
fileOut.close(); } catch (Exception e) {
e.printStackTrace();
}
}
/**
* 报表导入
*/
@RequestMapping("/ExcelInfo")
@LogAnno(value="对学生数据进行了excel表格导入",grade="info")
public RespModel ExcelInfo(MultipartFile file,HttpServletRequest request){
RespModel rm=new RespModel();
InputStream fileIn=null;
try {
fileIn=file.getInputStream();
//根据指定的文件输入流导入Excel从而产生Workbook对象
Workbook wb0 = new HSSFWorkbook(fileIn);
//获取Excel文档中的第一个表单
Sheet sht0 = wb0.getSheetAt();
//对Sheet中的每一行进行迭代
for (Row r : sht0) {
//如果当前行的行号(从0开始)未达到2(第三行)则从新循环
if(r.getRowNum()<){
continue;
}
//创建实体类
Student stu=new Student();
//取出当前行第1个单元格数据,并封装在info实体stuName属性上
stu.setStuName(r.getCell()==null?null:r.getCell().getStringCellValue());
stu.setStuCompany(r.getCell()==null?null:r.getCell().getStringCellValue());
stu.setStuEducation(r.getCell()==null?null:r.getCell().getStringCellValue());
stu.setStuEntrytime(r.getCell()==null?null:new SimpleDateFormat("yyyy-MM-dd").parse(r.getCell().getStringCellValue()));
stu.setStuIsstar("是".equals(r.getCell())==true?:);
stu.setStuNote(r.getCell()==null?null:r.getCell().getStringCellValue());
stu.setStuPicture(r.getCell()==null?null:r.getCell().getStringCellValue());
stu.setStuRecollections(r.getCell()==null?null:r.getCell().getStringCellValue());
stu.setStuSalary(r.getCell()==null?null:Float.valueOf(r.getCell().getStringCellValue()));
stu.setStuSchool(r.getCell()==null?null:r.getCell().getStringCellValue());
String state = r.getCell()==null?"":r.getCell().getStringCellValue();
int sta=;
switch (state) {
case "缉编中": sta=;break;
case "待审核": sta=;break;
case "待发布": sta=;break;
case "取消发布": sta=;break;
case "过期": sta=;break;
}
stu.setStuState(sta);
stu.setStuTrainingtime(r.getCell()==null?null:new SimpleDateFormat("yyyy-MM-dd").parse(r.getCell().getStringCellValue()));
stu.setStuWiter(r.getCell()==null?null:r.getCell().getStringCellValue());
stu.setStuWorkaddress(r.getCell()==null?null:r.getCell().getStringCellValue());
//添加学生
stuService.addStuInfo(stu);
} rm.setFlag(true);
rm.setMsg("数据导入成功!");
fileIn.close();
} catch (Exception e) {
System.out.println("异常");
rm.setFlag(false);
rm.setMsg("数据导入失败!");
e.printStackTrace();
}
return rm;
}
WEB 报表导入导出操作的更多相关文章
- Web直接导入导出SHP/CAD实现探讨。
1.导入SHP/CAD文件 WEB具有直接美观展现功能,功能实现到可视化最好不要超过3S,那么就要限制导入文件的大小和优化算法了. 1.1.SHP导入实现思路 SHP格式开源,Git上随便可以找到读取 ...
- c# .Net :Excel NPOI导入导出操作教程之读取Excel文件信息及输出
c# .Net :Excel NPOI导入导出操作教程之读取Excel文件信息及输出 using NPOI.HSSF.UserModel;using NPOI.SS.UserModel;using S ...
- Winform开发框架之通用数据导入导出操作的事务性操作完善
1.通用数据导入导出操作模块回顾 在我的Winfrom开发框架里面,有一个通用的导入模块,它在默默处理这把规范的Excel数据导入到不同的对象表里面,一直用它来快速完成数据导入的工作.很早在随笔< ...
- 循序渐进开发WinForm项目(5)--Excel数据的导入导出操作
随笔背景:在很多时候,很多入门不久的朋友都会问我:我是从其他语言转到C#开发的,有没有一些基础性的资料给我们学习学习呢,你的框架感觉一下太大了,希望有个循序渐进的教程或者视频来学习就好了. 其实也许我 ...
- VB中Excel 2010的导入导出操作
VB中Excel 2010的导入导出操作 编写人:左丘文 2015-4-11 近来这已是第二篇在讨论VB的相关问题,今天在这里,我想与大家一起分享一下在VB中如何从Excel中导入数据和导出数据到Ex ...
- Excel 报表导入导出
使用 Excel 进行报表的导入导出,首先下载相关的 jar 和 excel util. Excel Util 下载地址 引入依赖: <!-- poi office --> <dep ...
- asp.net core web的导入导出excel功能
这里主要记录下asp.net core web页面上进行导入导出excel的操作. 主要是导入,因为现在使用的很多前端框架(例如kendo ui)本身就有导出的功能. 这里使用到EPPlus.Core ...
- ORACLE 导入导出操作
1.导入命令: imp userId/psw@orcl full=y file=D:\data\xxx.dmp ignore=y 2.导出命令 exp userId/psw@orcl file=d: ...
- net core WebApi——使用NPOI导入导出操作
目录 前言 NPOI 测试 小结 @ 前言 时间过得好快,在之前升级到3.0之后,就感觉好久没再动过啥东西了,之前有问到Swagger的中文汉化,虽说我觉得这种操作的意义不是太大,也是多少鼓捣了下,其 ...
随机推荐
- WPF 数据绑定 使用Code First with Database
一.准备工作 1.开发工具 Visual Studio 2013 2.安装 Entity Framework 6 Tools for Visual Studio 2012 & 2013 来实现 ...
- 复刻smartbits的国产网络测试工具minismb-如何测试协议限速
复刻smartbits的网络性能测试工具MiniSMB,是一款专门用于测试智能路由器,网络交换机的性能和稳定性的软硬件相结合的工具.可以通过此工具测试任何ip网络设备的端口吞吐率,带宽,并发连接数和最 ...
- CentOS QT can't find lGL
直接安装: yum install libGL, yum install libGL-devel 库即可.
- JVM学习记录-Java内存模型(二)
对于volatile型变量的特殊规则 关键字volatile可以说是Java虚拟机提供的最轻量级的同步机制. 在处理多线程数据竞争问题时,不仅仅是可以使用synchronized关键字来实现,使用vo ...
- map映照容器(常用的使用方法总结)
map映照容器的数据元素是由一个键值和一个映照数据组成的,键值和映照数据之间具有一一对应的关系.map与set集合容器一样,不允许插入的元素的键值重复. /*关于C++STL中map映照容器的学习,看 ...
- 进程监控工具supervisor
supervisor是一个python编写的进程管理工具, 可以方便的管理和监控进程. supervisor分为服务端supervisord和客户端supervisorctl. supervisor由 ...
- 从零开始学JAVA(09)-使用SpringMVC4 + Mybatis + MySql 例子(注解方式开发)
项目需要,继续学习springmvc,这里加入Mybatis对数据库的访问,并写下一个简单的例子便于以后学习,希望对看的人有帮助.上一篇被移出博客主页,这一篇努力排版整齐,更原创,希望不要再被移出主页 ...
- RocketMQ 概述
Rocket 火箭 MQ的作用:同步转异步(异步解耦). 难点:如何确保消息一定被消费,而且仅消费一次. 1.消息架构:生产者.服务器.消费者.路由发现. 2.消息顺序:严格按照消息到达服务器的顺序进 ...
- 阿里云数据库配置学习笔记(二):下载并配置MySQL数据库
参考资料:阿里云官方文档 2018-02-20 一.MySQL数据库的下载 在Ubuntu环境下安装MySQL数据库十分简单 在命令行中输入 sudo apt-get update(更新软件源,预防出 ...
- HDU3359(SummerTrainingDay05-I 高斯消元)
Kind of a Blur Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...