From a072d87b809ceaa224066d0ed987b3bb7ed54d78 Mon Sep 17 00:00:00 2001 From: "LAPTOP-L3VE7KK2\\USER" Date: Fri, 22 Nov 2024 11:07:59 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B2=AC=EC=A0=81=EC=84=9C=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EC=97=90=EB=9F=AC=EC=8B=9C=20=EC=98=A4=EB=A5=98?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=84=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qcast/biz/estimate/EstimateService.java | 4 +- .../com/interplug/qcast/util/ExcelUtil.java | 49 +++++++++++++++++-- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/interplug/qcast/biz/estimate/EstimateService.java b/src/main/java/com/interplug/qcast/biz/estimate/EstimateService.java index 4c0d3087..781a8917 100644 --- a/src/main/java/com/interplug/qcast/biz/estimate/EstimateService.java +++ b/src/main/java/com/interplug/qcast/biz/estimate/EstimateService.java @@ -618,7 +618,7 @@ public class EstimateService { estimateMapper.updateEstimateApi(estimateRequest); } } catch (Exception e) { - e.printStackTrace(); + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR); } } @@ -1062,7 +1062,7 @@ public class EstimateService { } } catch (Exception e) { - e.printStackTrace(); + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR); } } diff --git a/src/main/java/com/interplug/qcast/util/ExcelUtil.java b/src/main/java/com/interplug/qcast/util/ExcelUtil.java index 3f75ead1..bfc1c3df 100644 --- a/src/main/java/com/interplug/qcast/util/ExcelUtil.java +++ b/src/main/java/com/interplug/qcast/util/ExcelUtil.java @@ -23,13 +23,13 @@ import org.springframework.stereotype.Component; public class ExcelUtil { /** - * jxls을 이용한 엑셀다운로드 + * jxls을 이용한 엑셀데이터 축출 * * @param request HttpServletRequest * @param response HttpServletResponse * @param map 엑셀 출력데이터 * @param list 엑셀 출력 목록 데이터 - * @param templateFileName + * @param templateFileName 템플릿 파일명 * @throws ParsePropertyException * @throws InvalidFormatException */ @@ -49,8 +49,6 @@ public class ExcelUtil { InputStream templateStream = PdfUtil.class.getClassLoader().getResourceAsStream(templateFilePath); - // InputStream is = new BufferedInputStream(templateStream); - try (InputStream is = new BufferedInputStream(templateStream)) { Context context = new Context(); context.putVar("data", map); @@ -68,6 +66,49 @@ public class ExcelUtil { return excelBytes; } + /** + * jxls을 이용한 엑셀다운로드 + * + * @param request HttpServletRequest + * @param response HttpServletResponse + * @param map 엑셀 출력데이터 + * @param list 엑셀 출력 목록 데이터 + * @param fileName 다운로드 파일명 + * @param templateFileName 템플릿 파일명 + * @throws ParsePropertyException + * @throws InvalidFormatException + */ + public void download( + HttpServletRequest request, + HttpServletResponse response, + Map map, + List> list, + String fileName, + String templateFileName) + throws ParsePropertyException, InvalidFormatException { + try { + + String templateFilePath = "template/excel/" + templateFileName; + InputStream templateStream = + PdfUtil.class.getClassLoader().getResourceAsStream(templateFilePath); + + InputStream is = new BufferedInputStream(templateStream); + + response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".xlsx\""); + response.addHeader("Access-Control-Expose-Headers", "Content-Disposition"); + + try (OutputStream os = response.getOutputStream()) { + Context context = new Context(); + context.putVar("data", map); + context.putVar("list", list); + + JxlsHelper.getInstance().processTemplate(is, os, context); + } + } catch (Exception e) { + log.debug(e.getMessage()); + } + } + /** * Object => Map 변환 함수 *