From 7305a614ca20d50e6ab50bbcfbb128a6f1f90e53 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Sun, 15 Jun 2025 04:41:55 +0000 Subject: (최겸) 기술영업 벤더 개발 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tech-vendors/table/excel-template-download.tsx | 276 +++++++++++---------- 1 file changed, 149 insertions(+), 127 deletions(-) (limited to 'lib/tech-vendors/table/excel-template-download.tsx') diff --git a/lib/tech-vendors/table/excel-template-download.tsx b/lib/tech-vendors/table/excel-template-download.tsx index 65b880da..db2c5fb5 100644 --- a/lib/tech-vendors/table/excel-template-download.tsx +++ b/lib/tech-vendors/table/excel-template-download.tsx @@ -1,128 +1,150 @@ -import * as ExcelJS from 'exceljs'; -import { saveAs } from "file-saver"; - -// 벤더 타입 enum -const VENDOR_TYPES = ["조선", "해양TOP", "해양HULL"] as const; - -/** - * 기술영업 벤더 데이터 가져오기를 위한 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: 'email', width: 25 }, - { header: '사업자등록번호', key: 'taxId', width: 15 }, - { header: '벤더타입', key: 'techVendorType', width: 15 }, - { header: '주소', key: 'address', width: 30 }, - { header: '국가', key: 'country', width: 15 }, - { header: '전화번호', key: 'phone', width: 15 }, - { header: '웹사이트', key: 'website', width: 25 }, - { header: '아이템', key: 'items', width: 30 }, - ]; - - // 헤더 스타일 적용 - 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 = [ - { - vendorName: '샘플 업체 1', - email: 'sample1@example.com', - taxId: '123-45-67890', - techVendorType: '조선', - address: '서울시 강남구', - country: '대한민국', - phone: '02-1234-5678', - website: 'https://example1.com', - items: 'ITEM001,ITEM002' - }, - { - vendorName: '샘플 업체 2', - email: 'sample2@example.com', - taxId: '234-56-78901', - techVendorType: '해양TOP', - address: '부산시 해운대구', - country: '대한민국', - phone: '051-234-5678', - website: 'https://example2.com', - 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' } - }; - }); - } - }); - - // 워크시트에 벤더 타입 관련 메모 추가 - const infoRow = worksheet.addRow(['벤더 타입 안내: ' + VENDOR_TYPES.join(', ')]); - infoRow.font = { bold: true, color: { argb: 'FF0000FF' } }; - worksheet.mergeCells(`A${infoRow.number}:I${infoRow.number}`); - - // 워크시트 보호 (선택적) - 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; - } +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: 'items', width: 30 }, + ]; + + // 헤더 스타일 적용 + 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 = [ + { + 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: '조선', + 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: '해양TOP', + 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; + } } \ No newline at end of file -- cgit v1.2.3