/**
* 报表导出
* @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. Linux 普通用户启动nginx

    众所周知,apache的80端口为系统保留端口,如果通过其他非root用户启动,会报错如下: ()Permission denied: make_sock: could not bind to add ...

  2. ArcGIS紧凑型切片读取与应用3-紧凑型批量转分散型(附源码)

    1.前言 上篇介绍了webgis动态加载解析紧凑型切片的例子,现在我们使用逆向思维实现紧凑型切片转分散型切片,在实际工作中很有用处,紧凑型切片易于拷贝,但读取只有部署到Arcgis Server才行. ...

  3. normalize.css 中文版

    ## normalize.css 中文版 normalize.css 原地址:http://necolas.github.io/normalize.css/reset 太暴力了,这个 normaliz ...

  4. C# WebAPI设置跨域

    设置前端跨域请求很简单,只需要两个步骤 1.安装package Install-Package Microsoft.AspNet.WebApi.Cors 2.WebApiConfig类中,Regist ...

  5. python模块之xlwt

    一. 安装 pip install xlwt 二. 使用 1. 创建excel(工作簿)对象 import xlwt wb = xlwt.Workbook() # 生成Workbook对象(xlwt. ...

  6. JS DOM操作(二) Window.docunment对象——操作样式

    一 对元素的定位 在 js 中可以利用 id.class.name.标签名进行元素的定位 id.class  用在客户端 name  用在服务端 用 id 定位                  -- ...

  7. thinphp 缓存机制导致代码不跟新

    问题: 调试阶段,程序已经更新,但是浏览器没有出现新效果! 1.以为是谷歌浏览器缓存导致,解决:设置--高级设置--隐私设置--清除浏览器缓存 一小时过去了,但还是没有更新,怎么刷新都没用!! 2. ...

  8. 撩课-Java每天5道面试题第19天

    126.Struts2中的拦截器有什么用?列举框架提供的拦截器名称? )拦截器是struts2核心组成部分, 它提供了一种机制,使得开发者 可以定义一个特定的功能模块, 这个模块会在Action执行之 ...

  9. python-桥接模式

    源码地址:https://github.com/weilanhanf/PythonDesignPatterns 说明: 有些类在功能设计上要求,自身包含两个或两个以上变化的因素,即该类在二维或者多维上 ...

  10. 微信小程序上传图片(前端+PHP后端)

    一.wxml文件 <text>上传图片</text> <view> <button bindtap="uploadimg">点击选择 ...