/**
* 报表导出
* @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 报表导入导出操作的更多相关文章

  1. Web直接导入导出SHP/CAD实现探讨。

    1.导入SHP/CAD文件 WEB具有直接美观展现功能,功能实现到可视化最好不要超过3S,那么就要限制导入文件的大小和优化算法了. 1.1.SHP导入实现思路 SHP格式开源,Git上随便可以找到读取 ...

  2. c# .Net :Excel NPOI导入导出操作教程之读取Excel文件信息及输出

    c# .Net :Excel NPOI导入导出操作教程之读取Excel文件信息及输出 using NPOI.HSSF.UserModel;using NPOI.SS.UserModel;using S ...

  3. Winform开发框架之通用数据导入导出操作的事务性操作完善

    1.通用数据导入导出操作模块回顾 在我的Winfrom开发框架里面,有一个通用的导入模块,它在默默处理这把规范的Excel数据导入到不同的对象表里面,一直用它来快速完成数据导入的工作.很早在随笔< ...

  4. 循序渐进开发WinForm项目(5)--Excel数据的导入导出操作

    随笔背景:在很多时候,很多入门不久的朋友都会问我:我是从其他语言转到C#开发的,有没有一些基础性的资料给我们学习学习呢,你的框架感觉一下太大了,希望有个循序渐进的教程或者视频来学习就好了. 其实也许我 ...

  5. VB中Excel 2010的导入导出操作

    VB中Excel 2010的导入导出操作 编写人:左丘文 2015-4-11 近来这已是第二篇在讨论VB的相关问题,今天在这里,我想与大家一起分享一下在VB中如何从Excel中导入数据和导出数据到Ex ...

  6. Excel 报表导入导出

    使用 Excel 进行报表的导入导出,首先下载相关的 jar 和 excel util. Excel Util 下载地址 引入依赖: <!-- poi office --> <dep ...

  7. asp.net core web的导入导出excel功能

    这里主要记录下asp.net core web页面上进行导入导出excel的操作. 主要是导入,因为现在使用的很多前端框架(例如kendo ui)本身就有导出的功能. 这里使用到EPPlus.Core ...

  8. ORACLE 导入导出操作

    1.导入命令: imp userId/psw@orcl full=y  file=D:\data\xxx.dmp ignore=y 2.导出命令 exp userId/psw@orcl file=d: ...

  9. net core WebApi——使用NPOI导入导出操作

    目录 前言 NPOI 测试 小结 @ 前言 时间过得好快,在之前升级到3.0之后,就感觉好久没再动过啥东西了,之前有问到Swagger的中文汉化,虽说我觉得这种操作的意义不是太大,也是多少鼓捣了下,其 ...

随机推荐

  1. python 生成唯一识别码

    import uuid identity = str(uuid.uuid4()).encode('ascii')

  2. 【区块链Go语言实现】Part 1:区块链基本原型

    0x00 介绍 区块链(Blockchain)是21世纪最具革命性的技术之一,目前它仍处于逐渐成熟阶段,且其发展潜力尚未被完全意识到.从本质上讲,区块链只是一种记录的分布式数据库.但它之所以独特,是因 ...

  3. iOS开源项目周报0413

    由OpenDigg 出品的iOS开源项目周报第十六期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. glidin ...

  4. 自动加载的iframe高度自适应

    动态产生iframe,自动加载至body中,还有一个功能就是iframe的高度自适应,下面代码测试于IE和Firefox,Chrome:

  5. MFC获取系统信息

    一.获取系统时间 CString str,str2; CTime time; time = CTime::GetCurrentTime(); str = time.Format("%Y年%m ...

  6. echarts展示箱型图&正态分布曲线

    效果图: 直接上代码吧: <!DOCTYPE HTML> <html> <head> <style type="text/css"> ...

  7. [日常] Go语言圣经--包和文件-包初始化习题

    1.解决包级变量的依赖顺序,然后按照包级变量声明出现的顺序依次初始化 2.包中含有多个.go源文件,它们将按照发给编译器的顺序进行初始化 3.init初始化函数,在每个文件中的init初始化函数,在程 ...

  8. Eclipse启动tomcat后404错误

    题描述 在eclipse部署web项目后,发现tomcat可以启动,但是访问http://localhost:8080地址报404错误.而不使用eclipse启动tomcat,直接通过通过tomcat ...

  9. Linux-mkdosfs格式化磁盘命令(15)

    名称:mkdosfs 使用:mkdosfs [块设备名称] 说明: 将一个块设备格式化为DOS磁盘类型 例: mkdosfs /dev/memblock //将memblock块设备格式化为dos磁盘 ...

  10. java的锁机制——synchronized

    一段synchronized的代码被一个线程执行之前,他要先拿到执行这段代码的权限,在java里边就是拿到某个同步对象的锁(一个对象只有一把锁): 如果这个时候同步对象的锁被其他线程拿走了,他(这个线 ...