public String downLoadTemplateExcel(String excelPath) { OutputStream out = null; try { File file = new File(excelPath); InputStream in = new FileInputStream(file); Workbook wb = WorkbookFactory.create(in); //获取模板名称 String filename = file.getName(); //截取没有后缀的文件名称 int subscript = filename.indexOf("."); filename = this.encodingFilename(filename.substring(0,subscript)); //获取模板下载绝对路径(文件名+时间+文件后缀) String downloadPath = getAbsoluteFile(filename); //创建输出文件流 out = new FileOutputStream(downloadPath); //将模板内容写入到对应的文件 wb.write(out); return downloadPath; } catch (Exception e) { log.error("下载Excel模板异常{}", e.getMessage()); throw new CustomException("下载Excel失败,请联系网站管理员!"); } finally { if (wb != null) { try { wb.close(); } catch (IOException e) { e.printStackTrace(); } } if (out != null) { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } }
10-30
06-27
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交