IT
Java 엑셀 라이브러리를 활용하여 날짜 값 통으로 출력하기 예시
agnusdei1207
2022. 8. 18. 14:22
반응형
SMALL
/* 엑셀 다운로드 */
@SuppressWarnings("unchecked")
@RequestMapping(folderPath + "excelDown.do")
public ModelAndView excelDown(@ModelAttribute("searchVO") CmmnDefaultVO searchVO, ModelMap model) throws Exception{
ModelAndView mav = new ModelAndView(excelView);
/* 제목 URL 셋팅 */
String tit = "통계자료";
String url = "totalStatistics.xlsx";
String time = ""; // 기간
/* default 날짜 값 설정 */
String year = searchVO.getExcelYear();
String nowDay = DateUtils.getNowDate("dd");
String month = searchVO.getExcelMonth();
/* 날짜 포멧 */
if(!"ALL".equals(searchVO.getExcelMonth()) && Integer.parseInt(month) < 10){
month = "0" + month;
searchVO.setExcelMonth(month);
}
/* 날짜 설정 */
if("ALL".equals(searchVO.getExcelMonth())){
time = year + "년";
}else{
time = year + "년" + month + "월" + "01일 ~" + year + "년" + month + "월" + nowDay + "일";
}
/* 조회 할 날짜 값 셋팅 */
searchVO.setSchEtc01(searchVO.getExcelYear()+"."+month);
/* 월 : 전체 검색 시 날짜 값 셋팅 */
if("ALL".equals(searchVO.getExcelMonth())){
searchVO.setSchEtc01(searchVO.getExcelYear());
}
/* 엑셀 통계 조회 */
List<St01VO> eatLst = (List<St01VO>) cmmnService.selectList(searchVO, PROGRAM_ID + ".excelEatLogSelectList");
List<St01VO> overTimeLst = (List<St01VO>) cmmnService.selectList(searchVO, PROGRAM_ID + ".excelOverTimeSelectList");
St01VO eatLog = (St01VO) cmmnService.selectContents(searchVO, PROGRAM_ID + ".statisticsEatLogExcelDown" );
St01VO overTime = (St01VO) cmmnService.selectContents(searchVO, PROGRAM_ID + ".statisticsOverTimeExcelDown" );
/* 값 담아주기 key : value */
mav.addObject("target", tit);
mav.addObject("source", url);
mav.addObject("time", time);
mav.addObject("eatLst", eatLst);
mav.addObject("overTimeLst", overTimeLst);
mav.addObject("overTime", overTime);
mav.addObject("eatLog", eatLog);
return mav;
}
1. String time 변수 선언
2. 계산된 날짜 값 + 포멧 형태에 맞추어 출력
반응형
LIST