引入插件
compile ":excel-export:0.2.1"
导出方法
/** * 导出Excel * */
def export(){
def list=ExpressOrder.list()//
def headers=['运单号','收件人姓名','收件人电话','目的省市县','详细地址']
def headers = [message(code: 'expressOrder.waybillNo.label'),
message(code: 'expressOrder.receive.conctas.label'),
message(code: 'expressOrder.receive.phoneNo.label'),
message(code: 'expressOrder.receive.addr.label'),
message(code: 'expressOrder.receive.address.label')]
def withProperties=['waybillNo','receive.conctas','receive.phoneNo','receive.addr','receive.address']
def fileName="快递单"+yyyyMMddhhmmssSdf.format(new Date())+".xlsx"
new WebXlsxExporter().with {
setResponseHeaders(response,new ExcelUtil().encodeFileName(request,fileName))//防止导出Excel文件名中文乱码 fillHeader(headers)
add(list, withProperties)
save(response.outputStream)
}
}