ftl模板导出excel_java通过FreeMarker模板生成Excel文件之.ftl模板制作

资产端简称放款金额(元)账单月份UZY服务费(元)账单状态

${(data.assetName)!""}${(data.loanAmount?string('0.00'))!""}${(data.billMonth)!""}${(data.uzyServiceFee?string('0.00'))!""}${(data.statusName)!""}

#list>

简单吧,效果如下

后台部分代码:

private void exportToXls(String templateName, String fileName, Map dataMap, HttpServletResponse response) {

Configuration configuration = new Configuration();

configuration.setEncoding(Locale.CHINA, "UTF-8");

configuration.setDefaultEncoding("UTF-8");

configuration.setClassForTemplateLoading(this.getClass(), "/templates");

String downloadFileName;

try {

downloadFileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");

} catch (UnsupportedEncodingException e) {

logger.warn("encode error", e);

downloadFileName = DateUtil.format(new Date());

}

response.setContentType("application/ms-excel");

response.setCharacterEncoding("UTF-8");

response.setHeader("Content-disposition", "attachment; filename=" + downloadFileName + ".xls");

try {

Template template = configuration.getTemplate(templateName);

template.process(dataMap, response.getWriter());

} catch (Exception e) {

logger.warn("export report error", e);

}

}

你可能感兴趣的:(ftl模板导出excel)