jeesite导出Excel

公西运良
2023-12-01

首先定义出需要导出字段的实体类并在导出的字段上面加入@ExcelField注解


    private String orderNo;	

    private String userName;

    private String userPhoneNo;

    @ExcelField(title="用户姓名", align=2, sort=10)
    public String getUserName() {
        return userName;
    }


    @ExcelField(title="用户手机号", align=2, sort=10)
    public String getUserPhoneNo() {
        return userPhoneNo;
    }

 
    @ExcelField(title="订单号", align=2, sort=10)
    public String getOrderNo() {
        return orderNo;
    }

参数说明:title 导出表头     align = 2 居中显示   sort 导出的先后顺序

实例如下

@RequestMapping(value = "privacyExport")
	public String privacyExport(Order order,HttpServletResponse response,HttpServletRequest request, RedirectAttributes redirectAttributes) {
		try {
			String fileName = "订单列表" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
			List<Order> exportList = orderDao.getOrders(order);
			new ExportExcel("订单列表", Order.class).setDataList(exportList).write(response, fileName)
					.dispose();
			return null;
		} catch (Exception e) {
			e.printStackTrace();
			addMessage(redirectAttributes, "导出失败!失败信息:"+e.getMessage());
		}
		return "redirect:"+Global.getAdminPath()+"/order/?repage";
	}

 类似资料: