- class XlsController{
- /**
- * 字符串编码
- */
- final def encode(String value,String charSet='UTF-8'){
- java.net.URLEncoder.encode(value, charSet)
- }
- def xlsExportService
- def i18nKeyList = ['username','nickname']
- def exportXls = {
- def fileName = encode('东明')
- response.setHeader("Contentdisposition","attachment;filename=${fileName}.xls")
- response.setContentType("application/vnd.ms-excel")
- def dataList = personService.list(cache:true)
- def titleList = i18nKeyList.collect{ key -> message(code:key) }
- xlsExportService.genForList(dataList,titleList,response.outputStream)
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/16112012414.html
来源: http://www.codesnippet.cn/detail/16112012414.html