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>
    <% } %>

  • 相关阅读:
    JStorm集群的安装和使用
    Kafka集群的安装和使用
    Linux下which、whereis、locate、find 命令的区别
    Linux 命令小记
    Linux 普通进程 后台进程 守护进程
    Java 命令行运行参数大全
    一台机子上运行使用不同Java版本的多个tomcat
    Ubuntu 设置程序开机启动(以指定用户身份)
    linux 开机启动过程详解
    关于Linux发行版的选择
  • 原文地址:https://www.cnblogs.com/pureray-hui/p/12469836.html
Copyright © 2011-2022 走看看