zoukankan      html  css  js  c++  java
  • jeesite平台导出功能

    /*
    * 导出:注:Controller的接口地址     student/student/student/
    */

    @RequiresPermissions("student:student:student:download")
    @RequestMapping("/download")
    public String download(Model model,Student student,HttpServletRequest request,HttpServletResponse response ) {
    List<Student> list=studentService.findList(student);
    // 创建excel
    HSSFWorkbook wk = new HSSFWorkbook();
    // 创建一张工作表
    HSSFSheet sheet = wk.createSheet();
    // 2
    sheet.setColumnWidth(0, 5000);
    HSSFRow row = sheet.createRow(0);
    // 创建第一行的第一个单元格
    // 想单元格写值
    HSSFCell cell = row.createCell((short) 0);
    cell.setCellValue("序号");
    cell = row.createCell((short)1);
    cell.setCellValue("姓名");
    cell = row.createCell((short)2);
    cell.setCellValue("性别");
    cell = row.createCell((short)3);
    cell.setCellValue("生日 ");
    cell = row.createCell((short)4);
    cell.setCellValue("班级");

    // 创建第一行
    for (short i=0;i<list.size();i++)
    {
    row = sheet.createRow(i+1);
    row.createCell(0).setCellValue(list.get(i).getSno());
    row.createCell(1).setCellValue(list.get(i).getSname());
    row.createCell(2).setCellValue(list.get(i).getSsex());
    row.createCell(3).setCellValue(list.get(i).getSbirthday());
    row.createCell(4).setCellValue(list.get(i).getSclass());
    }
    try {
    /**
    * 弹出下载选择路径框
    */
    response.setContentType("application/octet-stream");
    response.setHeader("Content-disposition", "attachment;filename=Student.xls");//默认Excel名称
    response.flushBuffer();
    wk.write(response.getOutputStream());
    wk.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    finally {

    }
    return "null";
    }

    在html中:

    <% if(hasPermi('student:student:student:download')){ %>
    <a href="${ctx}/student/student/student/download" class="btn btn-default btnTool" title="${text('导出student')}"><i class="fa fa-download" aria-hidden="true"></i> ${text('导出')}</a>
    <% } %>

  • 相关阅读:
    Struts2学习笔记《三》
    《Shiro框架》shiro学习中报错解决方法
    android
    MAC 设置环境变量path的几种方法
    利用ant脚本 自动构建svn增量/全量 系统程序升级包
    Jenkins2 插件 Pipeline+BlueOcean 实现持续交付的初次演练
    Jenkins2 实现持续交付初次演练(MultiJob,Pipeline,Blue Ocean)
    jenkins2 -pipeline 常用groovy脚本
    jenkins2 pipeline介绍
    scala学习(1)----map和flatMap的区别
  • 原文地址:https://www.cnblogs.com/pureray-hui/p/12469836.html
Copyright © 2011-2022 走看看