项目导出execl

后台erp项目将数据导出步骤:

1,在前端页面设置导出按钮:

<a id="btn-export" href="javascript:;" class="btn btn-warning radius ml-5">导出</a>

2,书写js文件:

$('#btn-export').click(function() {
        var param = userManage.getQueryCondition({
              "start" : 0,
              "limit" : 500
            });
        var str = '';
        for (var i in param) {
          str += i + '=' + param[i] + '&';
        }
        window.location.href = '/transactionNewReport/export?' + str;
      });
var userManage = {
  currentItem : null,
  fuzzySearch : true,
  getQueryCondition : function(data) {
    var param = {};
    // 组装排序参数.
    param.sort = '[{"property":"id","direction":"DESC"}]';

    //param.status = $("#status").val();

    param.dateType = $("#dateType").val();
    param.beginDateSel = $("#logmin").val();
    param.endDateSel = $("#logmax").val();

    param.houseName = $("#houseName").val();

    param.deptId = $("#id_dept_sel").val();
    param.userName = $("#id_user_sel").val();

    var companyObj = $("#id_company_type");
    if (companyObj) {
      param.companyType = companyObj.val();
    }
    var inTypeObj = $('#id_inType_sel');
    if (inTypeObj) {
      param.inTypeSel = $('#id_inType_sel').val();
    }
    param.start = data.start;
    param.limit = 10000;
    return param;
  }
};

3,书写后端代码:

/**
   * 导出.
   * 
   * @param dto
   * @param response
   * @throws IOException
   */
  @RequestMapping(value = "export/detail")
  public void exportDetail(TransactionReportDto dto, HttpServletResponse response) throws IOException {

    String fileName = "表格名称" + (dto.getBeginDateSel() == null ? "" : DateUtil.date2Str(dto.getBeginDateSel())) + " - "
        + (dto.getEndDateSel() == null ? "" : DateUtil.date2Str(dto.getEndDateSel())) + ".xlsx";
    //这里得到需要导出的数据(控制层,业务层,数据层代码)
    List<TransactionResponseDetail> list = transactionNewReportService.findDetails(dto);

    List<Object[]> datas = new ArrayList<>();
    String[] titles = new String[] { "物业", "业绩类型", "业绩日期", "用户类型", "部门", "姓名", "比例", "业绩" };

    for (TransactionResponseDetail result : list) {
      List<Object> objs = new ArrayList<>();
      objs.add(result.getHouseName());
      objs.add(result.getBargainType().getName());
      objs.add(DateUtil.date2Str(result.getBargainDate()));
      objs.add(result.getUserType().getName());
      objs.add(result.getDeptName());
      objs.add(result.getUserName());
      objs.add(result.getRate());
      objs.add(result.getAmt());
      datas.add(objs.toArray());
    }
    response.reset();
    response.setContentType("application/x-msdownload");
    response.setHeader("Content-Disposition",
        "attachment; filename=" + new String(fileName.getBytes("GBK"), "ISO8859-1"));
    OutputStream out = response.getOutputStream();
    ExcelWrite.writeExcel(datas, titles, out);
    out.close();
  }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值