Skip to content

Instantly share code, notes, and snippets.

@houdq
Last active December 21, 2016 02:38
Show Gist options
  • Save houdq/5c140b383bc66f910a3753f6c2a1cd85 to your computer and use it in GitHub Desktop.
Save houdq/5c140b383bc66f910a3753f6c2a1cd85 to your computer and use it in GitHub Desktop.
grails 导出 excel

引入插件

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)
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment