feat: 엑셀다운로드 기능 추가

main
minuk926 3 years ago
parent 7ad064138d
commit 35c19a4c66

@ -22,7 +22,7 @@ import 'assets/scss/style.scss';
// optional configuration
const options = {
position: positions.MIDDLE, // positions.BOTTOM_CENTER,
position: positions.BOTTOM_CENTER, // positions.BOTTOM_CENTER,
timeout: 2000,
type: types.INFO, // info / success / error
offset: '50px',

@ -171,7 +171,7 @@ const ParkingRegister = () => {
</Button>
</Grid>
<Grid item>
<ExcelDownload fileName="심사등록대상" gridColumns={columns} excelDatas={rowsStatus.rows} />
<ExcelDownload fileName="심사등록대상" gridColumns={columns} excelDatas={rowsStatus.rows} isDisabled={totalCount === 0} />
</Grid>
</Grid>
</Grid>

@ -3,9 +3,16 @@ import { IconFileExport } from '@tabler/icons';
import { Button } from '@mui/material';
import * as Excel from 'exceljs';
import saveAs from 'file-saver';
import { useAlert } from 'react-alert';
const ExcelDownload = ({ fileName, gridColumns, excelDatas, isDisabled = true }) => {
const alert = useAlert();
const ExcelDownload = ({ fileName, gridColumns, excelDatas }) => {
const handleExcelDownload = () => {
if (!excelDatas || excelDatas.length === 0) {
alert.show('다운로드할 대상이 없습니다.[데이타 조회후 실행]');
return;
}
const workbook = new Excel.Workbook();
const worksheet = workbook.addWorksheet('Sheet'); // sheet My Sheet
/*
@ -88,7 +95,14 @@ const ExcelDownload = ({ fileName, gridColumns, excelDatas }) => {
};
return (
<Button variant="contained" color="primary" size="small" startIcon={<IconFileExport />} onClick={handleExcelDownload}>
<Button
disabled={isDisabled}
variant="contained"
color="primary"
size="small"
startIcon={<IconFileExport />}
onClick={handleExcelDownload}
>
엑셀다운로드
</Button>
);
@ -97,7 +111,8 @@ const ExcelDownload = ({ fileName, gridColumns, excelDatas }) => {
ExcelDownload.propTypes = {
fileName: PropTypes.string.isRequired,
gridColumns: PropTypes.array.isRequired,
excelDatas: PropTypes.array.isRequired
excelDatas: PropTypes.array.isRequired,
isDisabled: PropTypes.bool.isRequired
};
export default ExcelDownload;

Loading…
Cancel
Save