private final String staffSupervisionImportTemplateName = "static/public/templates/importDemo/staffSupervisionImportTemplatle";
private final String postfix = ".xlsx";
public static final String CONTENT_TYPE_XLS = "application/vnd.ms-excel";(在一个公用类型类中)
/**
* 人员监督下载导入模板
*
* @param response
*/
public void downloadTemplate(HttpServletResponse response) {
XSSFWorkbook wb;
try {
wb = ExcelUtil.readFileXSSF("classpath:" + staffSupervisionImportTemplateName + this.postfix);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
wb.write(bos);
byte[] byteArray = bos.toByteArray();
InputStream in = new ByteArrayInputStream(byteArray);
response.setContentType(ContentType.CONTENT_TYPE_XLS);
String fileName = "人员监督计划导入模板";
response.setHeader("Content-disposition",
"attachment; filename=\"" + WordUtil.changeNameToDownload(fileName + this.postfix)
+ "\"");
FileCopyUtils.copy(in, response.getOutputStream());
} catch (Exception e) {
dbLogger.error(LogUtil.formatMessage("导出人员监督计划导入模板失败。", e), LogUtil.buildDefaultLogArgs());
}
}