From 5831c191a505ba2ef00e6cb9fb85cbcedb108a2d Mon Sep 17 00:00:00 2001 From: minuk926 Date: Mon, 25 Jul 2022 13:55:47 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=8B=AC=EC=9D=98=EA=B2=B0=EA=B3=BC=20?= =?UTF-8?q?excel=20download=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/admin/judge/ModalJudgeResult.jsx | 92 +++++++++++++-- src/views/cmm/file-ctl/ExcelDownload.jsx | 111 ------------------ 2 files changed, 85 insertions(+), 118 deletions(-) delete mode 100644 src/views/cmm/file-ctl/ExcelDownload.jsx diff --git a/src/views/biz/admin/judge/ModalJudgeResult.jsx b/src/views/biz/admin/judge/ModalJudgeResult.jsx index 335722a..e9ac790 100644 --- a/src/views/biz/admin/judge/ModalJudgeResult.jsx +++ b/src/views/biz/admin/judge/ModalJudgeResult.jsx @@ -10,13 +10,15 @@ import { FormControl, Grid, InputLabel, MenuItem, Select, TableFooter, Typograph import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; import combo from 'commons/combo_data'; -import { useCallback, useState } from 'react'; +import { useCallback, useRef, useState } from 'react'; import Button from '@mui/material/Button'; -import { IconSearch } from '@tabler/icons'; +import { IconFileExport, IconSearch } from '@tabler/icons'; import { findJudgeResults } from 'apis/judge'; import _ from 'lodash'; import { useAlert } from 'react-alert'; import JudgeModal from './JudgeModal'; +import saveAs from 'file-saver'; +import * as Excel from 'exceljs'; const StyledTableCell = styled(TableCell)(({ theme }) => ({ [`&.${tableCellClasses.head}`]: { @@ -113,6 +115,73 @@ const ModalJudgeResult = ({ totJudgeUsers, totJudgeUserData, judgeCars, judgeUse [] ); + const handleExcelDownload = () => { + const colNames = ['No.', '접수번호', '차량번호']; + judgeResult.totJudgeUsers.forEach((u) => colNames.push(u.NAME)); + colNames.push('결과'); + + const excelDatas = []; + judgeResult.totJudgeUserData.forEach((u, idx) => { + excelDatas.push(['', totLabel[idx], '', ...u]); + }); + + judgeResult.judgeCars.forEach((d, idx) => { + excelDatas.push([ + idx + 1, + d.msSeq, + d.msCarnum, + ..._.range(idx, judgeResult.judgeUserData.length, judgeResult.judgeCars.length).map((i) => judgeResult.judgeUserData[i].msuResult), + judgeResult.judgeUserData[idx].msResultNm + ]); + }); + + if (!excelDatas || excelDatas.length === 0) { + alert.show('다운로드할 대상이 없습니다.[데이타 조회후 실행]'); + return; + } + const workbook = new Excel.Workbook(); + const worksheet = workbook.addWorksheet('Sheet'); // sheet 이름이 My Sheet + + const headerRow = worksheet.addRow(); + worksheet.getRow(1).font = { bold: true }; + + colNames.forEach((col, idx) => { + worksheet.getColumn(idx + 1).width = 10; + const cell = headerRow.getCell(idx + 1); + cell.value = col; + }); + + worksheet.properties.outlineProperties = { + summaryBelow: false, + summaryRight: false + }; + + excelDatas.forEach((row, idx) => { + const dataRow = worksheet.addRow(); + + colNames.forEach((col, i) => { + const cell = dataRow.getCell(i + 1); + cell.value = row[i]; + return false; + }); + }); + + let fileName = ''; + + if (!selectedRow.msDatagb) { + fileName = '주정차'; + } else { + fileName = selectedRow.msDatagb === '1' ? '거주자' : '장애인'; + } + + workbook.xlsx.writeBuffer().then((buffer) => { + saveAs( + new Blob([buffer], { type: 'application/octet-stream' }), + `${fileName} 심사결과[${selectedRow.msChasu}차-${msuTeam.substring(2)}팀(${selectedRow.msSdate} ~ ${selectedRow.msEdate})].xlsx` + ); + }); + }; + return ( - + 심의차수: {selectedRow.msChasu}차 ㅣ 심의기간: {selectedRow.msSdate} ~ {selectedRow.msEdate} - - - + + +