import * as ExcelJS from 'exceljs'; import { saveAs } from "file-saver"; /** * 업체 유형 데이터 가져오기를 위한 Excel 템플릿 파일 생성 및 다운로드 */ export async function exportVendorTypeTemplate() { // 워크북 생성 const workbook = new ExcelJS.Workbook(); workbook.creator = 'Item Management System'; workbook.created = new Date(); // 워크시트 생성 const worksheet = workbook.addWorksheet('업체 유형'); // 컬럼 헤더 정의 및 스타일 적용 worksheet.columns = [ { header: '업체 유형(한글)', key: 'nameKo', width: 50 }, { header: '업체 유형(영문)', key: 'nameEn', width: 50 }, ]; // 헤더 스타일 적용 const headerRow = worksheet.getRow(1); headerRow.font = { bold: true }; headerRow.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFE0E0E0' } }; headerRow.alignment = { vertical: 'middle', horizontal: 'center' }; // 테두리 스타일 적용 headerRow.eachCell((cell) => { cell.border = { top: { style: 'thin' }, left: { style: 'thin' }, bottom: { style: 'thin' }, right: { style: 'thin' } }; }); // 샘플 데이터 추가 const sampleData = [ { nameKo: 'ITEM001', nameEn: '샘플 업체 유형 1', }, { nameKo: 'ITEM002', nameEn: '샘플 업체 유형 2', } ]; // 데이터 행 추가 sampleData.forEach(item => { worksheet.addRow(item); }); // 데이터 행 스타일 적용 worksheet.eachRow((row, rowNumber) => { if (rowNumber > 1) { // 헤더를 제외한 데이터 행 row.eachCell((cell) => { cell.border = { top: { style: 'thin' }, left: { style: 'thin' }, bottom: { style: 'thin' }, right: { style: 'thin' } }; }); } }); try { // 워크북을 Blob으로 변환 const buffer = await workbook.xlsx.writeBuffer(); const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); saveAs(blob, 'vendor-type-template.xlsx'); return true; } catch (error) { console.error('Excel 템플릿 생성 오류:', error); throw error; } }