import * as ExcelJS from 'exceljs'; import { saveAs } from "file-saver"; /** * 기술영업 벤더 데이터 가져오기를 위한 Excel 템플릿 파일 생성 및 다운로드 */ export async function exportTechVendorTemplate() { // 워크북 생성 const workbook = new ExcelJS.Workbook(); workbook.creator = 'Tech Vendor Management System'; workbook.created = new Date(); // 워크시트 생성 const worksheet = workbook.addWorksheet('기술영업 벤더'); // 컬럼 헤더 정의 및 스타일 적용 worksheet.columns = [ { header: '업체명', key: 'vendorName', width: 20 }, { header: '업체코드', key: 'vendorCode', width: 15 }, { header: '사업자등록번호', key: 'taxId', width: 15 }, { header: '국가', key: 'country', width: 15 }, { header: '영문국가명', key: 'countryEng', width: 15 }, { header: '제조국', key: 'countryFab', width: 15 }, { header: '에이전트명', key: 'agentName', width: 20 }, { header: '에이전트연락처', key: 'agentPhone', width: 15 }, { header: '에이전트이메일', key: 'agentEmail', width: 25 }, { header: '주소', key: 'address', width: 30 }, { header: '전화번호', key: 'phone', width: 15 }, { header: '이메일', key: 'email', width: 25 }, { header: '웹사이트', key: 'website', width: 25 }, { header: '벤더타입', key: 'techVendorType', width: 15 }, { header: '대표자명', key: 'representativeName', width: 20 }, { header: '대표자이메일', key: 'representativeEmail', width: 25 }, { header: '대표자연락처', key: 'representativePhone', width: 15 }, { header: '대표자생년월일', key: 'representativeBirth', width: 15 }, { header: '담당자명', key: 'contactName', width: 20 }, { header: '담당자직책', key: 'contactPosition', width: 15 }, { header: '담당자이메일', key: 'contactEmail', width: 25 }, { header: '담당자연락처', key: 'contactPhone', width: 15 }, { header: '담당자국가', key: 'contactCountry', width: 15 }, { header: '아이템', key: 'items', width: 30 }, ]; // 헤더 스타일 적용 const headerRow = worksheet.getRow(1); headerRow.font = { bold: true }; headerRow.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFE0E0E0' } }; // 샘플 데이터 추가 worksheet.addRow([ 'ABC 조선소', // 업체명 'ABC001', // 업체코드 '123-45-67890', // 사업자등록번호 '대한민국', // 국가 'South Korea', // 영문국가명 '대한민국', // 제조국 '김대리', // 에이전트명 '02-123-4567', // 에이전트연락처 'agent@abc.co.kr', // 에이전트이메일 '서울시 강남구 테헤란로 123', // 주소 '02-123-4567', // 전화번호 'contact@abc.co.kr', // 이메일 'https://www.abc.co.kr', // 웹사이트 '조선', // 벤더타입 '홍길동', // 대표자명 'ceo@abc.co.kr', // 대표자이메일 '02-123-4567', // 대표자연락처 '1970-01-01', // 대표자생년월일 '박담당', // 담당자명 '과장', // 담당자직책 'contact@abc.co.kr', // 담당자이메일 '010-1234-5678', // 담당자연락처 '대한민국', // 담당자국가 '선박부품, 엔진부품' // 아이템 ]); // 설명을 위한 시트 추가 const instructionSheet = workbook.addWorksheet('입력 가이드'); instructionSheet.columns = [ { header: '컬럼명', key: 'column', width: 20 }, { header: '필수여부', key: 'required', width: 10 }, { header: '설명', key: 'description', width: 50 }, ]; // 가이드 헤더 스타일 const guideHeaderRow = instructionSheet.getRow(1); guideHeaderRow.font = { bold: true }; guideHeaderRow.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFE0E0E0' } }; // 입력 가이드 데이터 const guideData = [ ['업체명', '필수', '벤더 업체명을 입력하세요'], ['업체코드', '선택', '벤더 고유 코드 (없으면 자동 생성)'], ['사업자등록번호', '필수', '벤더의 사업자등록번호'], ['국가', '선택', '벤더 소재 국가'], ['영문국가명', '선택', '벤더 소재 국가의 영문명'], ['제조국', '선택', '제품 제조 국가'], ['에이전트명', '선택', '담당 에이전트 이름'], ['에이전트연락처', '선택', '담당 에이전트 연락처'], ['에이전트이메일', '선택', '담당 에이전트 이메일'], ['주소', '선택', '벤더 주소'], ['전화번호', '선택', '벤더 대표 전화번호'], ['이메일', '필수', '벤더 대표 이메일 (대표 담당자가 없으면 이 이메일이 기본 담당자가 됩니다)'], ['웹사이트', '선택', '벤더 웹사이트 URL'], ['벤더타입', '필수', '벤더 유형 (조선, 해양TOP, 해양HULL 중 선택)'], ['대표자명', '선택', '벤더 대표자 이름'], ['대표자이메일', '선택', '벤더 대표자 이메일'], ['대표자연락처', '선택', '벤더 대표자 연락처'], ['대표자생년월일', '선택', '벤더 대표자 생년월일 (YYYY-MM-DD 형식)'], ['담당자명', '선택', '주 담당자 이름 (없으면 대표자 또는 업체명으로 기본 담당자 생성)'], ['담당자직책', '선택', '주 담당자 직책'], ['담당자이메일', '선택', '주 담당자 이메일 (있으면 벤더 이메일보다 우선)'], ['담당자연락처', '선택', '주 담당자 연락처'], ['담당자국가', '선택', '주 담당자 소재 국가'], ['아이템', '선택', '벤더가 제공하는 아이템 (쉼표로 구분)'], ]; guideData.forEach(row => { instructionSheet.addRow(row); }); 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 = [ { vendorName: '샘플 업체 1', vendorCode: 'TV001', taxId: '123-45-67890', country: '대한민국', countryEng: 'Korea', countryFab: '대한민국', agentName: '에이전트1', agentPhone: '02-1234-5678', agentEmail: 'agent1@example.com', address: '서울시 강남구', phone: '02-1234-5678', email: 'sample1@example.com', website: 'https://example1.com', techVendorType: '조선,해양TOP', representativeName: '홍길동', representativeEmail: 'ceo1@example.com', representativePhone: '010-1234-5678', representativeBirth: '1980-01-01', items: 'ITEM001,ITEM002' }, { vendorName: '샘플 업체 2', vendorCode: 'TV002', taxId: '234-56-78901', country: '대한민국', countryEng: 'Korea', countryFab: '대한민국', agentName: '에이전트2', agentPhone: '051-234-5678', agentEmail: 'agent2@example.com', address: '부산시 해운대구', phone: '051-234-5678', email: 'sample2@example.com', website: 'https://example2.com', techVendorType: '해양HULL', representativeName: '김철수', representativeEmail: 'ceo2@example.com', representativePhone: '010-2345-6789', representativeBirth: '1985-02-02', items: 'ITEM003,ITEM004' } ]; // 데이터 행 추가 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' } }; }); } }); // 워크시트 보호 (선택적) worksheet.protect('', { selectLockedCells: true, selectUnlockedCells: true, formatColumns: true, formatRows: true, insertColumns: false, insertRows: true, insertHyperlinks: false, deleteColumns: false, deleteRows: true, sort: true, autoFilter: true, pivotTables: false }); try { // 워크북을 Blob으로 변환 const buffer = await workbook.xlsx.writeBuffer(); const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); saveAs(blob, 'tech-vendor-template.xlsx'); return true; } catch (error) { console.error('Excel 템플릿 생성 오류:', error); throw error; } }