@Override
public void test(Map<String, Object> params, HttpServletResponse response) throws IOException {
ClassPathResource classPathResource = new ClassPathResource("/statics/xlsx/导入模板.xlsx");
InputStream fis = classPathResource.getInputStream();
XSSFWorkbook workBook = new XSSFWorkbook(fis);
XSSFSheet sheet = workBook.cloneSheet(0);
String fileName="导入模板";
try {
//设置Http响应头告诉浏览器下载这个附件
response.setHeader("Content-Disposition", "attachment;Filename=" + new String(fileName.getBytes("utf-8"),"ISO-8859-1" ) + ".xlsx");
OutputStream outputStream = response.getOutputStream();
workBook.removeSheetAt(0); // 移除workbook中的模板sheet
workBook.write(outputStream);
outputStream.close();
} catch (Exception ex) {
ex.printStackTrace();
throw new IOException("导出Excel出现严重异常,异常信息:" + ex.getMessage());
}
}
下载项目导入模板,自定义模板名
最新推荐文章于 2023-06-16 13:47:20 发布