엑셀다운로드시 progress bar
parent
15a58a9c3b
commit
804309bbd5
|
|
@ -4,13 +4,13 @@ import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
|
|
@ -22,6 +22,9 @@ import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
|
|
@ -41,6 +44,7 @@ import geoinfo.com.EgovExcel;
|
||||||
import geoinfo.comm.util.ScriptUtil;
|
import geoinfo.comm.util.ScriptUtil;
|
||||||
import geoinfo.comm.util.strUtil;
|
import geoinfo.comm.util.strUtil;
|
||||||
import geoinfo.session.UserInfo;
|
import geoinfo.session.UserInfo;
|
||||||
|
import geoinfo.util.ExcelJobManager;
|
||||||
import geoinfo.util.ExcelMergeHeaderUtil;
|
import geoinfo.util.ExcelMergeHeaderUtil;
|
||||||
import geoinfo.util.MyUtil;
|
import geoinfo.util.MyUtil;
|
||||||
|
|
||||||
|
|
@ -889,10 +893,18 @@ public class ConstructionProjectManagementController {
|
||||||
* @param response
|
* @param response
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@RequestMapping(value = "admins/drilling/inquiry/excel.do")
|
@RequestMapping(method = RequestMethod.POST, value="/admins/drilling/inquiry/excel/start.do")
|
||||||
public void downloadDrillingInquiryListExcel(HttpServletRequest request, HttpServletResponse response, HSSFWorkbook workbook, @RequestParam HashMap<String, Object> params) throws Exception {
|
@ResponseBody
|
||||||
|
public Map<String,Object> downloadDrillingInquiryListExcel(HttpServletRequest request, @RequestParam HashMap<String, Object> params) throws Exception {
|
||||||
|
|
||||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
final String jobId = UUID.randomUUID().toString();
|
||||||
|
final HttpServletRequest finalRequest = request;
|
||||||
|
final HashMap<String,Object> finalParams = params;
|
||||||
|
final DrillingInquiryService service = drillingInquiryService;
|
||||||
|
String excelFileName = "발주기관_건설현장_목록_" + ExcelMergeHeaderUtil.getTimeStampString("yyyyMMdd_HHmm") + ".xlsx";
|
||||||
|
|
||||||
|
ExcelJobManager.startJob(jobId, new ExcelJobManager.ExcelTask() {
|
||||||
|
public byte[] generate(ExcelJobManager.ProgressCallback callback) throws Exception {
|
||||||
|
|
||||||
String[] headers = {"cid","constName","projectStateCodeName","constStartDate","constStateCodeName","inquiryDist" ,"masterCompanyDept","masterCompanyAdmin","masterCompanyTel","coinstCompanyDept","constCompanyAdmin","constCompanyTel"};
|
String[] headers = {"cid","constName","projectStateCodeName","constStartDate","constStateCodeName","inquiryDist" ,"masterCompanyDept","masterCompanyAdmin","masterCompanyTel","coinstCompanyDept","constCompanyAdmin","constCompanyTel"};
|
||||||
String[][] headerNames = {{"연번", "사업명", "입력상태", "사업내용", "", "발주기관현황", "", "", "", "건설사현황", "", ""},
|
String[][] headerNames = {{"연번", "사업명", "입력상태", "사업내용", "", "발주기관현황", "", "", "", "건설사현황", "", ""},
|
||||||
|
|
@ -902,44 +914,38 @@ public class ConstructionProjectManagementController {
|
||||||
String[] columnType = {"String", "String", "String", "String", "String", "String", "String", "String", "String", "String", "String", "String"};
|
String[] columnType = {"String", "String", "String", "String", "String", "String", "String", "String", "String", "String", "String", "String"};
|
||||||
String sheetName = "Sheet1";
|
String sheetName = "Sheet1";
|
||||||
|
|
||||||
String excelFileName = "발주기관 건설현장 목록";
|
JSONObject resultObj = drillingInquiryService.drillingInquiryList(finalRequest, finalParams);
|
||||||
|
|
||||||
// int startIndex = 0;
|
|
||||||
Long totalCount = 0L;
|
|
||||||
// DB 조회
|
|
||||||
JSONObject resultObj = drillingInquiryService.drillingInquiryList(request, params);
|
|
||||||
|
|
||||||
// 여기에서 list 꺼내기
|
|
||||||
List<EgovMap> list = (List<EgovMap>) resultObj.get("datas");
|
List<EgovMap> list = (List<EgovMap>) resultObj.get("datas");
|
||||||
totalCount = (Long) resultObj.get("count");
|
Long totalCount = (Long) resultObj.get("count");
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (EgovMap rowData : list) {
|
for (EgovMap rowData : list) {
|
||||||
// 공사기간 형식 처리: startDate ~ endDate
|
|
||||||
String constStartDate = (String) rowData.get("constStartDate");
|
String constStartDate = (String) rowData.get("constStartDate");
|
||||||
String constEndDate = (String) rowData.get("constEndDate");
|
String constEndDate = (String) rowData.get("constEndDate");
|
||||||
rowData.put("constStartDate", constStartDate + " ~ " + constEndDate); // 공사기간을 'startDate ~ endDate' 형식으로 변환
|
rowData.put("constStartDate", constStartDate + " ~ " + constEndDate);
|
||||||
rowData.put("cid", (totalCount) - (idx++));
|
rowData.put("cid", (totalCount) - (idx++));
|
||||||
|
|
||||||
String glName = "";
|
String inquiryDist = "";
|
||||||
String gmName = "";
|
if (rowData.get("glName") != null)
|
||||||
String gsName = "";
|
inquiryDist += rowData.get("glName") + " ";
|
||||||
String inquiryDist = ""; // 발주처
|
if (rowData.get("gmName") != null)
|
||||||
if ((String)rowData.get("glName") != null) {
|
inquiryDist += rowData.get("gmName") + " ";
|
||||||
glName = (String)rowData.get("glName");
|
if (rowData.get("gsName") != null)
|
||||||
inquiryDist = inquiryDist + glName + " ";
|
inquiryDist += rowData.get("gsName");
|
||||||
}if ((String)rowData.get("gmName") != null) {
|
|
||||||
gmName = (String)rowData.get("gmName");
|
|
||||||
inquiryDist = inquiryDist + gmName + " ";
|
|
||||||
}if ((String)rowData.get("gsName") != null) {
|
|
||||||
gsName = (String)rowData.get("gsName");
|
|
||||||
inquiryDist = inquiryDist + gsName;
|
|
||||||
}
|
|
||||||
rowData.put("inquiryDist", inquiryDist);
|
rowData.put("inquiryDist", inquiryDist);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExcelMergeHeaderUtil.listToExcelMergeHeader(list, response, headers, headerNames, headerWidths, columnType, sheetName, excelFileName);
|
byte[] excelBytes = ExcelMergeHeaderUtil.listToExcelMergeHeaderByteArray(list, headers, headerNames, headerWidths, columnType, "Sheet1", callback);
|
||||||
|
|
||||||
|
return excelBytes;
|
||||||
|
|
||||||
|
}
|
||||||
|
}, excelFileName);
|
||||||
|
|
||||||
|
Map<String,Object> result = new HashMap<String,Object>();
|
||||||
|
result.put("jobId", jobId);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1113,4 +1119,45 @@ public class ConstructionProjectManagementController {
|
||||||
ExcelMergeHeaderUtil.listToExcelMergeHeaderForLoginHistory(resultList, response, headers, headerNames, headerWidths, columnType, sheetName, excelFileName);
|
ExcelMergeHeaderUtil.listToExcelMergeHeaderForLoginHistory(resultList, response, headers, headerNames, headerWidths, columnType, sheetName, excelFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 엑셀 다운로드 로딩 표시(진행률 확인)
|
||||||
|
* @param jobId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping(value="/admins/drilling/inquiry/excel/progress.do", method=RequestMethod.GET)
|
||||||
|
@ResponseBody
|
||||||
|
public Map<String,Object> getExcelProgress(@RequestParam String jobId) {
|
||||||
|
int progress = ExcelJobManager.getProgress(jobId);
|
||||||
|
Map<String,Object> result = new HashMap<>();
|
||||||
|
result.put("progress", progress);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 엑셀 다운로드 로딩 표시(다운로드 완료)
|
||||||
|
* @param jobId
|
||||||
|
* @param response
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@RequestMapping(value="/admins/drilling/inquiry/excel/download.do", method=RequestMethod.GET)
|
||||||
|
public void downloadExcel(@RequestParam String jobId, HttpServletResponse response) throws IOException {
|
||||||
|
byte[] data = ExcelJobManager.getResult(jobId);
|
||||||
|
if(data == null){
|
||||||
|
response.sendError(404, "엑셀 파일을 찾을 수 없습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Job 단위로 저장된 파일명 사용
|
||||||
|
String fileName = ExcelJobManager.getFileName(jobId);
|
||||||
|
fileName = java.net.URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
|
||||||
|
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
||||||
|
response.setHeader("Content-Transfer-Encoding", "binary");
|
||||||
|
response.setContentType("application/octet-stream");
|
||||||
|
response.getOutputStream().write(data);
|
||||||
|
response.flushBuffer();
|
||||||
|
|
||||||
|
// 완료 후 캐시 제거
|
||||||
|
ExcelJobManager.clear(jobId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
package geoinfo.util;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
import egovframework.rte.psl.dataaccess.util.EgovMap;
|
||||||
|
import geoinfo.admins.user.service.DrillingInquiryService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 엑셀 다운로드 로딩바 처리 유틸
|
||||||
|
* @author JIYOO
|
||||||
|
*/
|
||||||
|
public class ExcelJobManager {
|
||||||
|
|
||||||
|
private static class Job {
|
||||||
|
byte[] data;
|
||||||
|
String fileName;
|
||||||
|
int progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, Job> jobMap = new ConcurrentHashMap<String, Job>();
|
||||||
|
|
||||||
|
public static void startJob(final String jobId, final ExcelTask excelTask, final String fileName) {
|
||||||
|
final Job job = new Job();
|
||||||
|
job.progress = 0;
|
||||||
|
job.fileName = fileName;
|
||||||
|
jobMap.put(jobId, job);
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
byte[] excelBytes = excelTask.generate(new ProgressCallback() {
|
||||||
|
@Override
|
||||||
|
public void update(int percent) {
|
||||||
|
job.progress = percent;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
job.data = excelBytes;
|
||||||
|
job.progress = 100;
|
||||||
|
} catch (Exception e) {
|
||||||
|
job.progress = -1;
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getProgress(String jobId) {
|
||||||
|
Job job = jobMap.get(jobId);
|
||||||
|
return job == null ? 0 : job.progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getResult(String jobId) {
|
||||||
|
Job job = jobMap.get(jobId);
|
||||||
|
return job == null ? null : job.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFileName(String jobId) {
|
||||||
|
Job job = jobMap.get(jobId);
|
||||||
|
return job == null ? "excel.xlsx" : job.fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clear(String jobId) {
|
||||||
|
jobMap.remove(jobId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface ProgressCallback {
|
||||||
|
void update(int percent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface ExcelTask {
|
||||||
|
byte[] generate(ProgressCallback callback) throws Exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package geoinfo.util;
|
package geoinfo.util;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
|
@ -30,25 +30,32 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
|
||||||
import egovframework.rte.psl.dataaccess.util.EgovMap;
|
import egovframework.rte.psl.dataaccess.util.EgovMap;
|
||||||
|
|
||||||
|
|
||||||
public class ExcelMergeHeaderUtil {
|
public class ExcelMergeHeaderUtil {
|
||||||
|
|
||||||
|
|
||||||
public static boolean isEmpty(final Object obj) {
|
public static boolean isEmpty(final Object obj) {
|
||||||
return !isNotEmpty(obj);
|
return !isNotEmpty(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNotEmpty(final Object obj) {
|
public static boolean isNotEmpty(final Object obj) {
|
||||||
if(null == obj) return false;
|
if (null == obj)
|
||||||
|
return false;
|
||||||
else {
|
else {
|
||||||
if(obj instanceof String) return "".equals(obj) ? false : true;
|
if (obj instanceof String)
|
||||||
else if(obj instanceof List) return !((List<?>)obj).isEmpty();
|
return "".equals(obj) ? false : true;
|
||||||
else if(obj instanceof Map) return !((Map<?,?>)obj).isEmpty();
|
else if (obj instanceof List)
|
||||||
// else if(obj instanceof Object[]) return 0 == Array.getLength(obj) ? false : true;
|
return !((List<?>) obj).isEmpty();
|
||||||
else if(obj instanceof Integer) return !(null == obj);
|
else if (obj instanceof Map)
|
||||||
else if(obj instanceof Long) return !(null == obj);
|
return !((Map<?, ?>) obj).isEmpty();
|
||||||
else if(obj instanceof LocalDate) return !(null == obj);
|
// else if(obj instanceof Object[]) return 0 == Array.getLength(obj) ? false :
|
||||||
else return false;
|
// true;
|
||||||
|
else if (obj instanceof Integer)
|
||||||
|
return !(null == obj);
|
||||||
|
else if (obj instanceof Long)
|
||||||
|
return !(null == obj);
|
||||||
|
else if (obj instanceof LocalDate)
|
||||||
|
return !(null == obj);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,45 +67,61 @@ public class ExcelMergeHeaderUtil {
|
||||||
return getTimeStampString(date, "yyyyMMddHHmmss");
|
return getTimeStampString(date, "yyyyMMddHHmmss");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTimeStampString(final Date date, final String format){
|
public static String getTimeStampString(final Date date, final String format) {
|
||||||
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat (format, java.util.Locale.KOREA);
|
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(format, java.util.Locale.KOREA);
|
||||||
return formatter.format(date);
|
return formatter.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTimeStampString(String date, final String format) {
|
public static String getTimeStampString(String date, final String format) {
|
||||||
try {
|
try {
|
||||||
if(null == date || "".equals(date)) return "";
|
if (null == date || "".equals(date))
|
||||||
|
return "";
|
||||||
|
|
||||||
Date d = null;
|
Date d = null;
|
||||||
date= date.replaceAll("-", "");
|
date = date.replaceAll("-", "");
|
||||||
|
|
||||||
switch(date.length()) {
|
switch (date.length()) {
|
||||||
case 14: break;
|
case 14:
|
||||||
case 12: date += "00"; break;
|
break;
|
||||||
case 10: date += "0000"; break;
|
case 12:
|
||||||
case 8: date += "000000"; break;
|
date += "00";
|
||||||
case 6: date += "01000000"; break;
|
break;
|
||||||
case 4: date += "0101000000"; break;
|
case 10:
|
||||||
default: return "";
|
date += "0000";
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
date += "000000";
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
date += "01000000";
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
date += "0101000000";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
java.text.SimpleDateFormat tmpFormat = new java.text.SimpleDateFormat("yyyyMMddHHmmss", java.util.Locale.KOREA);
|
java.text.SimpleDateFormat tmpFormat = new java.text.SimpleDateFormat("yyyyMMddHHmmss",
|
||||||
|
java.util.Locale.KOREA);
|
||||||
|
|
||||||
if("".equals(date)) d = new Date();
|
if ("".equals(date))
|
||||||
|
d = new Date();
|
||||||
else {
|
else {
|
||||||
tmpFormat.setLenient(true);
|
tmpFormat.setLenient(true);
|
||||||
d = tmpFormat.parse(date);
|
d = tmpFormat.parse(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getTimeStampString(d, format);
|
return getTimeStampString(d, format);
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFileExtention(final String filename) {
|
public static String getFileExtention(final String filename) {
|
||||||
if(null == filename || "".equals(filename)) return "";
|
if (null == filename || "".equals(filename))
|
||||||
|
return "";
|
||||||
|
|
||||||
return -1 < filename.lastIndexOf(".") ? filename.substring(filename.lastIndexOf(".") + 1).toLowerCase() : "";
|
return -1 < filename.lastIndexOf(".") ? filename.substring(filename.lastIndexOf(".") + 1).toLowerCase() : "";
|
||||||
}
|
}
|
||||||
|
|
@ -112,15 +135,16 @@ public class ExcelMergeHeaderUtil {
|
||||||
return ExcelMergeHeaderUtil.getTimeStampString("yyyyMMdd_HHmmss_SSS");
|
return ExcelMergeHeaderUtil.getTimeStampString("yyyyMMdd_HHmmss_SSS");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void listToExcel(List<EgovMap> list, HttpServletResponse response, String[] headers, String[] headerNames, String[] columnType, String sheetName, String excelFileName) throws IOException {
|
public static void listToExcel(List<EgovMap> list, HttpServletResponse response, String[] headers,
|
||||||
if(ExcelMergeHeaderUtil.isNotEmpty(list)) {
|
String[] headerNames, String[] columnType, String sheetName, String excelFileName) throws IOException {
|
||||||
|
if (ExcelMergeHeaderUtil.isNotEmpty(list)) {
|
||||||
// 메모리에 100개의 행을 유지합니다. 행의 수가 넘으면 디스크에 적습니다.
|
// 메모리에 100개의 행을 유지합니다. 행의 수가 넘으면 디스크에 적습니다.
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
Sheet sheet = wb.createSheet(sheetName);
|
Sheet sheet = wb.createSheet(sheetName);
|
||||||
Row headerRow = sheet.createRow(0);
|
Row headerRow = sheet.createRow(0);
|
||||||
CellStyle cellStyle1 = wb.createCellStyle(); //쉼표들어간 숫자 양식
|
CellStyle cellStyle1 = wb.createCellStyle(); // 쉼표들어간 숫자 양식
|
||||||
CellStyle cellStyle2 = wb.createCellStyle(); //숫자양식
|
CellStyle cellStyle2 = wb.createCellStyle(); // 숫자양식
|
||||||
CellStyle headerStyle = wb.createCellStyle(); //헤더 스타일
|
CellStyle headerStyle = wb.createCellStyle(); // 헤더 스타일
|
||||||
CellStyle borderStyle = wb.createCellStyle(); // 기본 검정 테두리 스타일
|
CellStyle borderStyle = wb.createCellStyle(); // 기본 검정 테두리 스타일
|
||||||
|
|
||||||
// 기본 검정 테두리 스타일 설정
|
// 기본 검정 테두리 스타일 설정
|
||||||
|
|
@ -144,14 +168,14 @@ public class ExcelMergeHeaderUtil {
|
||||||
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||||
headerStyle.setFillForegroundColor((short)3);
|
headerStyle.setFillForegroundColor((short) 3);
|
||||||
headerStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
headerStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||||
|
|
||||||
for(int i=0; i<list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
EgovMap rowData = list.get(i);
|
EgovMap rowData = list.get(i);
|
||||||
Row row = sheet.createRow(i+1);
|
Row row = sheet.createRow(i + 1);
|
||||||
|
|
||||||
for(int j=0; j<headers.length; j++) {
|
for (int j = 0; j < headers.length; j++) {
|
||||||
Cell cell = row.createCell(j);
|
Cell cell = row.createCell(j);
|
||||||
|
|
||||||
Object value = rowData.get(headers[j]);
|
Object value = rowData.get(headers[j]);
|
||||||
|
|
@ -182,18 +206,19 @@ public class ExcelMergeHeaderUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int j=0; j<headerNames.length; j++) {
|
for (int j = 0; j < headerNames.length; j++) {
|
||||||
Cell cell = headerRow.createCell(j);
|
Cell cell = headerRow.createCell(j);
|
||||||
cell.setCellValue(headerNames[j]);
|
cell.setCellValue(headerNames[j]);
|
||||||
cell.setCellStyle(headerStyle);
|
cell.setCellStyle(headerStyle);
|
||||||
sheet.autoSizeColumn(j);
|
sheet.autoSizeColumn(j);
|
||||||
sheet.setColumnWidth(j, (sheet.getColumnWidth(j)) + 1000);
|
sheet.setColumnWidth(j, (sheet.getColumnWidth(j)) + 1000);
|
||||||
}
|
}
|
||||||
//엑셀이름 한글깨짐방지
|
// 엑셀이름 한글깨짐방지
|
||||||
String outputFileName = new String(excelFileName.getBytes("KSC5601"), "8859_1");
|
String outputFileName = new String(excelFileName.getBytes("KSC5601"), "8859_1");
|
||||||
|
|
||||||
response.setHeader("Set-Cookie", "fileDownload=true; path=/");
|
response.setHeader("Set-Cookie", "fileDownload=true; path=/");
|
||||||
response.setHeader("Content-Disposition", String.format("attachment; filename=\""+outputFileName+"_"+ExcelMergeHeaderUtil.getTimeStampString("yyyyMMdd_HHmm")+".xlsx\""));
|
response.setHeader("Content-Disposition", String.format("attachment; filename=\"" + outputFileName + "_"
|
||||||
|
+ ExcelMergeHeaderUtil.getTimeStampString("yyyyMMdd_HHmm") + ".xlsx\""));
|
||||||
|
|
||||||
wb.write(response.getOutputStream());
|
wb.write(response.getOutputStream());
|
||||||
wb.close();
|
wb.close();
|
||||||
|
|
@ -203,15 +228,17 @@ public class ExcelMergeHeaderUtil {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void listToExcelMergeHeader(List<EgovMap> list, HttpServletResponse response, String[] headers, String[][] headerNames, int[] headerWidths, String[] columnType, String sheetName, String excelFileName) throws IOException {
|
public static void listToExcelMergeHeader(List<EgovMap> list, HttpServletResponse response, String[] headers,
|
||||||
if(ExcelMergeHeaderUtil.isNotEmpty(list)) {
|
String[][] headerNames, int[] headerWidths, String[] columnType, String sheetName, String excelFileName)
|
||||||
|
throws IOException {
|
||||||
|
if (ExcelMergeHeaderUtil.isNotEmpty(list)) {
|
||||||
// 메모리에 100개의 행을 유지합니다. 행의 수가 넘으면 디스크에 적습니다.
|
// 메모리에 100개의 행을 유지합니다. 행의 수가 넘으면 디스크에 적습니다.
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
Sheet sheet = wb.createSheet(sheetName);
|
Sheet sheet = wb.createSheet(sheetName);
|
||||||
Row headerRow = sheet.createRow(headerNames.length);
|
Row headerRow = sheet.createRow(headerNames.length);
|
||||||
CellStyle cellStyle1 = wb.createCellStyle(); //쉼표들어간 숫자 양식
|
CellStyle cellStyle1 = wb.createCellStyle(); // 쉼표들어간 숫자 양식
|
||||||
CellStyle cellStyle2 = wb.createCellStyle(); //숫자양식
|
CellStyle cellStyle2 = wb.createCellStyle(); // 숫자양식
|
||||||
CellStyle headerStyle = wb.createCellStyle(); //헤더 스타일
|
CellStyle headerStyle = wb.createCellStyle(); // 헤더 스타일
|
||||||
CellStyle borderStyle = wb.createCellStyle(); // 기본 검정 테두리 스타일
|
CellStyle borderStyle = wb.createCellStyle(); // 기본 검정 테두리 스타일
|
||||||
|
|
||||||
// 기본 검정 테두리 스타일 설정
|
// 기본 검정 테두리 스타일 설정
|
||||||
|
|
@ -235,7 +262,7 @@ public class ExcelMergeHeaderUtil {
|
||||||
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||||
// headerStyle.setFillForegroundColor((short)3);
|
// headerStyle.setFillForegroundColor((short)3);
|
||||||
headerStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
headerStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||||
|
|
||||||
// 바디 스타일
|
// 바디 스타일
|
||||||
|
|
@ -280,13 +307,13 @@ public class ExcelMergeHeaderUtil {
|
||||||
Cell cell = row.createCell(j);
|
Cell cell = row.createCell(j);
|
||||||
|
|
||||||
// 특정 컬럼 중앙 정렬 -----참고용------------
|
// 특정 컬럼 중앙 정렬 -----참고용------------
|
||||||
// if ("lvl1_rate".equals(headers[j]) ||
|
// if ("lvl1_rate".equals(headers[j]) ||
|
||||||
// "lvl2_rate".equals(headers[j]) ||
|
// "lvl2_rate".equals(headers[j]) ||
|
||||||
// "lvl3_rate".equals(headers[j]) ||
|
// "lvl3_rate".equals(headers[j]) ||
|
||||||
// "lvl2_organ_up".equals(headers[j]) ||
|
// "lvl2_organ_up".equals(headers[j]) ||
|
||||||
// "lvl3_organ_up".equals(headers[j])) {
|
// "lvl3_organ_up".equals(headers[j])) {
|
||||||
// cell.setCellStyle(bodyStyle);
|
// cell.setCellStyle(bodyStyle);
|
||||||
// } -----참고용------------
|
// } -----참고용------------
|
||||||
|
|
||||||
Object value = rowData.get(headers[j]);
|
Object value = rowData.get(headers[j]);
|
||||||
|
|
||||||
|
|
@ -317,11 +344,12 @@ public class ExcelMergeHeaderUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//엑셀이름 한글깨짐방지
|
// 엑셀이름 한글깨짐방지
|
||||||
String outputFileName = new String(excelFileName.getBytes("KSC5601"), "8859_1");
|
String outputFileName = new String(excelFileName.getBytes("KSC5601"), "8859_1");
|
||||||
|
|
||||||
response.setHeader("Set-Cookie", "fileDownload=true; path=/");
|
response.setHeader("Set-Cookie", "fileDownload=true; path=/");
|
||||||
response.setHeader("Content-Disposition", String.format("attachment; filename=\""+outputFileName+"_"+ExcelMergeHeaderUtil.getTimeStampString("yyyyMMdd_HHmm")+".xlsx\""));
|
response.setHeader("Content-Disposition", String.format("attachment; filename=\"" + outputFileName + "_"
|
||||||
|
+ ExcelMergeHeaderUtil.getTimeStampString("yyyyMMdd_HHmm") + ".xlsx\""));
|
||||||
|
|
||||||
wb.write(response.getOutputStream());
|
wb.write(response.getOutputStream());
|
||||||
wb.close();
|
wb.close();
|
||||||
|
|
@ -331,11 +359,110 @@ public class ExcelMergeHeaderUtil {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 로딩바 표시를 위하여 응답을 return함
|
||||||
|
*
|
||||||
|
* @param response
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
// public static byte[] listToExcelMergeHeaderByteArray(List<EgovMap> list,
|
||||||
|
// String[] headers, String[][] headerNames, int[] headerWidths, String[]
|
||||||
|
// columnType, String sheetName) throws IOException {
|
||||||
|
public static byte[] listToExcelMergeHeaderByteArray(List<EgovMap> list, String[] headers, String[][] headerNames,
|
||||||
|
int[] headerWidths, String[] columnType, String sheetName, ExcelJobManager.ProgressCallback callback)
|
||||||
|
throws IOException {
|
||||||
|
|
||||||
|
if (!ExcelMergeHeaderUtil.isNotEmpty(list)) {
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
|
Sheet sheet = wb.createSheet(sheetName);
|
||||||
|
|
||||||
|
CellStyle headerStyle = wb.createCellStyle();
|
||||||
|
CellStyle borderStyle = wb.createCellStyle();
|
||||||
|
CellStyle cellStyle1 = wb.createCellStyle();
|
||||||
|
CellStyle cellStyle2 = wb.createCellStyle();
|
||||||
|
|
||||||
|
// ===== 스타일 설정 =====
|
||||||
|
borderStyle.setBorderTop(BorderStyle.THIN);
|
||||||
|
borderStyle.setBorderBottom(BorderStyle.THIN);
|
||||||
|
borderStyle.setBorderLeft(BorderStyle.THIN);
|
||||||
|
borderStyle.setBorderRight(BorderStyle.THIN);
|
||||||
|
|
||||||
|
Font headerFont = wb.createFont();
|
||||||
|
headerFont.setColor(IndexedColors.WHITE.getIndex());
|
||||||
|
headerStyle.setFont(headerFont);
|
||||||
|
headerStyle.cloneStyleFrom(borderStyle);
|
||||||
|
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
|
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||||
|
headerStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||||
|
|
||||||
|
XSSFDataFormat format = wb.createDataFormat();
|
||||||
|
cellStyle1.setDataFormat(format.getFormat("#,##0"));
|
||||||
|
cellStyle2.setDataFormat(format.getFormat("#"));
|
||||||
|
|
||||||
|
// ===== 헤더 병합 =====
|
||||||
|
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
|
||||||
|
sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
|
||||||
|
sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
|
||||||
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 4));
|
||||||
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 5, 8));
|
||||||
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 9, 11));
|
||||||
|
|
||||||
|
// ===== 헤더 생성 =====
|
||||||
|
for (int i = 0; i < headerNames.length; i++) {
|
||||||
|
Row row = sheet.createRow(i);
|
||||||
|
for (int j = 0; j < headerNames[i].length; j++) {
|
||||||
|
Cell cell = row.createCell(j);
|
||||||
|
cell.setCellValue(headerNames[i][j]);
|
||||||
|
cell.setCellStyle(headerStyle);
|
||||||
|
sheet.setColumnWidth(j, headerWidths[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== 바디 =====
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
EgovMap rowData = list.get(i);
|
||||||
|
Row row = sheet.createRow(i + 2);
|
||||||
|
|
||||||
|
for (int j = 0; j < headers.length; j++) {
|
||||||
|
Cell cell = row.createCell(j);
|
||||||
|
Object value = rowData.get(headers[j]);
|
||||||
|
|
||||||
|
if ("Money".equalsIgnoreCase(columnType[j])) {
|
||||||
|
cell.setCellValue(value instanceof Number ? ((Number) value).doubleValue() : 0);
|
||||||
|
cell.setCellStyle(cellStyle1);
|
||||||
|
} else if ("Int".equalsIgnoreCase(columnType[j])) {
|
||||||
|
cell.setCellValue(value instanceof Number ? ((Number) value).doubleValue() : 0);
|
||||||
|
cell.setCellStyle(cellStyle2);
|
||||||
|
} else {
|
||||||
|
cell.setCellValue(value == null ? "" : String.valueOf(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
cell.setCellStyle(borderStyle);
|
||||||
|
// 진행률 계산 (중간중간 콜백 호출)
|
||||||
|
if (callback != null) {
|
||||||
|
int percent = (int) (((i + 1) / (double) list.size()) * 100);
|
||||||
|
callback.update(percent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
wb.write(bos);
|
||||||
|
wb.close();
|
||||||
|
|
||||||
|
return bos.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
private static void createNoDataAlert(HttpServletResponse response) throws IOException {
|
private static void createNoDataAlert(HttpServletResponse response) throws IOException {
|
||||||
response.setHeader("Content-Type", "text/html; charset=UTF-8");
|
response.setHeader("Content-Type", "text/html; charset=UTF-8");
|
||||||
PrintWriter out = response.getWriter();
|
PrintWriter out = response.getWriter();
|
||||||
|
|
||||||
out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">");
|
out.write(
|
||||||
|
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">");
|
||||||
out.write("<html lang=\"ko\">");
|
out.write("<html lang=\"ko\">");
|
||||||
out.write("<head>");
|
out.write("<head>");
|
||||||
out.write("<script type=\"text/javascript\">");
|
out.write("<script type=\"text/javascript\">");
|
||||||
|
|
@ -349,7 +476,8 @@ public class ExcelMergeHeaderUtil {
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDisposition(String filename, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
public static void setDisposition(String filename, HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws IOException {
|
||||||
String browser = getBrowser(request);
|
String browser = getBrowser(request);
|
||||||
|
|
||||||
String dispositionPrefix = "attachment; filename=";
|
String dispositionPrefix = "attachment; filename=";
|
||||||
|
|
@ -367,7 +495,7 @@ public class ExcelMergeHeaderUtil {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
for (int i = 0; i < filename.length(); i++) {
|
for (int i = 0; i < filename.length(); i++) {
|
||||||
char c = filename.charAt(i);
|
char c = filename.charAt(i);
|
||||||
if(c==','){
|
if (c == ',') {
|
||||||
sb.append(URLEncoder.encode(",", "UTF-8"));
|
sb.append(URLEncoder.encode(",", "UTF-8"));
|
||||||
} else if (c > '~') {
|
} else if (c > '~') {
|
||||||
sb.append(URLEncoder.encode("" + c, "UTF-8"));
|
sb.append(URLEncoder.encode("" + c, "UTF-8"));
|
||||||
|
|
@ -385,7 +513,7 @@ public class ExcelMergeHeaderUtil {
|
||||||
if ("Opera".equals(browser)) {
|
if ("Opera".equals(browser)) {
|
||||||
response.setContentType("application/octet-stream;charset=UTF-8");
|
response.setContentType("application/octet-stream;charset=UTF-8");
|
||||||
}
|
}
|
||||||
if(filename.contains("zip")){
|
if (filename.contains("zip")) {
|
||||||
response.setContentType("application/zip");
|
response.setContentType("application/zip");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -410,16 +538,17 @@ public class ExcelMergeHeaderUtil {
|
||||||
return formattedDate;
|
return formattedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void listToExcelMergeHeaderForLoginHistory(List<EgovMap> list, HttpServletResponse response,
|
||||||
public static void listToExcelMergeHeaderForLoginHistory(List<EgovMap> list, HttpServletResponse response, String[] headers, String[] headerNames, int[] headerWidths, String[] columnType, String sheetName, String excelFileName) throws IOException {
|
String[] headers, String[] headerNames, int[] headerWidths, String[] columnType, String sheetName,
|
||||||
if(ExcelMergeHeaderUtil.isNotEmpty(list)) {
|
String excelFileName) throws IOException {
|
||||||
|
if (ExcelMergeHeaderUtil.isNotEmpty(list)) {
|
||||||
// 메모리에 100개의 행을 유지합니다. 행의 수가 넘으면 디스크에 적습니다.
|
// 메모리에 100개의 행을 유지합니다. 행의 수가 넘으면 디스크에 적습니다.
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
Sheet sheet = wb.createSheet(sheetName);
|
Sheet sheet = wb.createSheet(sheetName);
|
||||||
Row headerRow = sheet.createRow(headerNames.length);
|
Row headerRow = sheet.createRow(headerNames.length);
|
||||||
CellStyle cellStyle1 = wb.createCellStyle(); //쉼표들어간 숫자 양식
|
CellStyle cellStyle1 = wb.createCellStyle(); // 쉼표들어간 숫자 양식
|
||||||
CellStyle cellStyle2 = wb.createCellStyle(); //숫자양식
|
CellStyle cellStyle2 = wb.createCellStyle(); // 숫자양식
|
||||||
CellStyle headerStyle = wb.createCellStyle(); //헤더 스타일
|
CellStyle headerStyle = wb.createCellStyle(); // 헤더 스타일
|
||||||
CellStyle borderStyle = wb.createCellStyle(); // 기본 검정 테두리 스타일
|
CellStyle borderStyle = wb.createCellStyle(); // 기본 검정 테두리 스타일
|
||||||
|
|
||||||
// 기본 검정 테두리 스타일 설정
|
// 기본 검정 테두리 스타일 설정
|
||||||
|
|
@ -443,7 +572,7 @@ public class ExcelMergeHeaderUtil {
|
||||||
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||||
// headerStyle.setFillForegroundColor((short)3);
|
// headerStyle.setFillForegroundColor((short)3);
|
||||||
headerStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
headerStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||||
|
|
||||||
// 바디 스타일
|
// 바디 스타일
|
||||||
|
|
@ -503,11 +632,12 @@ public class ExcelMergeHeaderUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//엑셀이름 한글깨짐방지
|
// 엑셀이름 한글깨짐방지
|
||||||
String outputFileName = new String(excelFileName.getBytes("KSC5601"), "8859_1");
|
String outputFileName = new String(excelFileName.getBytes("KSC5601"), "8859_1");
|
||||||
|
|
||||||
response.setHeader("Set-Cookie", "fileDownload=true; path=/");
|
response.setHeader("Set-Cookie", "fileDownload=true; path=/");
|
||||||
response.setHeader("Content-Disposition", String.format("attachment; filename=\""+outputFileName+"_"+ExcelMergeHeaderUtil.getTimeStampString("yyyyMMdd_HHmm")+".xlsx\""));
|
response.setHeader("Content-Disposition", String.format("attachment; filename=\"" + outputFileName + "_"
|
||||||
|
+ ExcelMergeHeaderUtil.getTimeStampString("yyyyMMdd_HHmm") + ".xlsx\""));
|
||||||
|
|
||||||
wb.write(response.getOutputStream());
|
wb.write(response.getOutputStream());
|
||||||
wb.close();
|
wb.close();
|
||||||
|
|
|
||||||
|
|
@ -574,6 +574,7 @@
|
||||||
|
|
||||||
// 엑셀 다운로드
|
// 엑셀 다운로드
|
||||||
function clickExcelDownload(){
|
function clickExcelDownload(){
|
||||||
|
/*
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
params.append("constTag", trim($('#const-tag').val()));
|
params.append("constTag", trim($('#const-tag').val()));
|
||||||
|
|
@ -595,6 +596,107 @@
|
||||||
// AJAX가 아닌 직접 다운로드 요청
|
// AJAX가 아닌 직접 다운로드 요청
|
||||||
window.location.href = "/admins/drilling/inquiry/excel.do?" + params.toString();
|
window.location.href = "/admins/drilling/inquiry/excel.do?" + params.toString();
|
||||||
$('#excelDownload').val("");
|
$('#excelDownload').val("");
|
||||||
|
*/
|
||||||
|
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
params.append("constTag", trim($('#const-tag').val()));
|
||||||
|
params.append("constName", trim($('#const-name').val()));
|
||||||
|
params.append("excelDownload", "Y");
|
||||||
|
|
||||||
|
parent[1].showLoadingBar();
|
||||||
|
|
||||||
|
fetch("/admins/drilling/inquiry/excel.do", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded"
|
||||||
|
},
|
||||||
|
body: params.toString()
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) throw new Error("다운로드 실패");
|
||||||
|
|
||||||
|
const disposition = response.headers.get("Content-Disposition");
|
||||||
|
let fileName = "excel.xlsx";
|
||||||
|
|
||||||
|
if (disposition && disposition.includes("filename=")) {
|
||||||
|
fileName = disposition.split("filename=")[1].replace(/"/g, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.blob().then(blob => ({ blob, fileName }));
|
||||||
|
})
|
||||||
|
.then(({ blob, fileName }) => {
|
||||||
|
|
||||||
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.href = url;
|
||||||
|
a.download = fileName;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
alert("엑셀 다운로드 중 오류 발생");
|
||||||
|
console.error(err);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
$('#excelDownload').val("");
|
||||||
|
parent.hideLoadingBar();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentJobId = null;
|
||||||
|
|
||||||
|
function startExcelDownload() {
|
||||||
|
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
params.append("constTag", trim($('#const-tag').val()));
|
||||||
|
params.append("constName", trim($('#const-name').val()));
|
||||||
|
params.append("excelDownload", "Y");
|
||||||
|
|
||||||
|
|
||||||
|
parent.showLoadingBar();
|
||||||
|
// parent.document.getElementById("progressWrap").style.display = "block";
|
||||||
|
|
||||||
|
fetch("/admins/drilling/inquiry/excel/start.do", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {"Content-Type":"application/x-www-form-urlencoded"},
|
||||||
|
body: params.toString()
|
||||||
|
})
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => {
|
||||||
|
currentJobId = data.jobId;
|
||||||
|
pollProgress();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#excelDownload').val("");
|
||||||
|
}
|
||||||
|
|
||||||
|
function pollProgress() {
|
||||||
|
|
||||||
|
fetch("/admins/drilling/inquiry/excel/progress.do?jobId=" + currentJobId)
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => {
|
||||||
|
|
||||||
|
let percent = data.progress;
|
||||||
|
|
||||||
|
if(percent < 0){
|
||||||
|
alert("엑셀 생성 중 오류 발생");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent.document.getElementById("progressBar").style.width = percent + "%";
|
||||||
|
parent.document.getElementById("progressText").innerText = percent + "%";
|
||||||
|
|
||||||
|
if(percent < 100){
|
||||||
|
setTimeout(pollProgress, 500);
|
||||||
|
} else {
|
||||||
|
setTimeout(function(){
|
||||||
|
window.location = "/admins/drilling/inquiry/excel/download.do?jobId=" + currentJobId;
|
||||||
|
parent.hideLoadingBar();
|
||||||
|
}, 700);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
</script><style>
|
</script><style>
|
||||||
.drilling .page-content-inner {
|
.drilling .page-content-inner {
|
||||||
|
|
@ -780,7 +882,8 @@ li {
|
||||||
</div>
|
</div>
|
||||||
<div class="table-info-group">
|
<div class="table-info-group">
|
||||||
<span>Total: <span id="count">-</span>건</span>
|
<span>Total: <span id="count">-</span>건</span>
|
||||||
<span class="pull-right"><img src="${pageContext.request.contextPath}/images/admins/excel.gif" style="cursor:hand" onClick="javascript:clickExcelDownload()"></span>
|
<%-- <span class="pull-right"><img src="${pageContext.request.contextPath}/images/admins/excel.gif" style="cursor:hand" onClick="javascript:clickExcelDownload()"></span> --%>
|
||||||
|
<span class="pull-right"><img src="${pageContext.request.contextPath}/images/admins/excel.gif" style="cursor:hand" onClick="startExcelDownload()"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="table-wrap">
|
<div class="table-wrap">
|
||||||
<table>
|
<table>
|
||||||
|
|
@ -835,7 +938,6 @@ li {
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<!-- 페이지 컨테이너 끝 -->
|
<!-- 페이지 컨테이너 끝 -->
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,79 @@
|
||||||
<script>
|
<script>
|
||||||
var waitWin;
|
var waitWin;
|
||||||
|
|
||||||
|
function showLoadingBar() {
|
||||||
|
document.getElementById("loadingModal").style.display = "flex";
|
||||||
|
document.getElementById("progressBar").style.width = "0%";
|
||||||
|
document.getElementById("progressText").innerText = "0%";
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideLoadingBar() {
|
||||||
|
document.getElementById("loadingModal").style.display = "none";
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<style type="text/css">
|
||||||
|
/* 전체 화면 반투명 배경 */
|
||||||
|
#loadingModal {
|
||||||
|
display: none; /* 기본 숨김 */
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
/* background: rgba(0,0,0,0.5); /* 반투명 검정 */ */
|
||||||
|
z-index: 9999;
|
||||||
|
/* display: flex; */
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 내용 박스 */
|
||||||
|
#loadingContent {
|
||||||
|
background: #fff;
|
||||||
|
padding: 30px 50px;
|
||||||
|
border-radius: 10px;
|
||||||
|
text-align: center;
|
||||||
|
min-width: 300px;
|
||||||
|
box-shadow: 0 0 20px rgba(0,0,0,0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 로딩 스피너 */
|
||||||
|
.spinner {
|
||||||
|
border: 6px solid #f3f3f3;
|
||||||
|
border-top: 6px solid #3498db;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
margin: 0 auto 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
0% { transform: rotate(0deg);}
|
||||||
|
100% { transform: rotate(360deg);}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 진행률 바 */
|
||||||
|
#progressWrap {
|
||||||
|
width: 100%;
|
||||||
|
height: 20px;
|
||||||
|
background: #eee;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#progressBar {
|
||||||
|
width: 0%;
|
||||||
|
height: 100%;
|
||||||
|
background: #4caf50;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#progressText {
|
||||||
|
margin-top: 5px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
|
<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
|
||||||
<!--
|
<!--
|
||||||
|
|
@ -18,5 +90,16 @@ var waitWin;
|
||||||
|
|
||||||
<iframe src="${pageContext.request.contextPath}/admins/${menuId}/${pId}.do?isFirst=true" frameborder="0" height="740" width="100%" scrolling="yes" name="iframeMain" style="overflow-x: hidden;"></iframe>
|
<iframe src="${pageContext.request.contextPath}/admins/${menuId}/${pId}.do?isFirst=true" frameborder="0" height="740" width="100%" scrolling="yes" name="iframeMain" style="overflow-x: hidden;"></iframe>
|
||||||
|
|
||||||
|
<!-- 로딩 모달 -->
|
||||||
|
<div id="loadingModal">
|
||||||
|
<div id="loadingContent">
|
||||||
|
<div class="spinner"></div>
|
||||||
|
<div id="loadingText">엑셀 파일 생성 중...</div>
|
||||||
|
<div id="progressWrap">
|
||||||
|
<div id="progressBar"></div>
|
||||||
|
</div>
|
||||||
|
<div id="progressText">0%</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue