summaryrefslogtreecommitdiff
path: root/lib/items-tech/table/hull/item-excel-template.tsx
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-05-14 06:12:13 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-05-14 06:12:13 +0000
commitd0d2eaa2de58a0c33e9a21604b126961403cd69e (patch)
treef66cd3c8d3a123ff04f800b4b868c573fab2da95 /lib/items-tech/table/hull/item-excel-template.tsx
parent21d8148fc5b1234cd4523e66ccaa8971ad104560 (diff)
(최겸) 기술영업 조선, 해양Top, 해양 Hull 아이템 리스트 개발(CRUD, excel import/export/template)
Diffstat (limited to 'lib/items-tech/table/hull/item-excel-template.tsx')
-rw-r--r--lib/items-tech/table/hull/item-excel-template.tsx125
1 files changed, 125 insertions, 0 deletions
diff --git a/lib/items-tech/table/hull/item-excel-template.tsx b/lib/items-tech/table/hull/item-excel-template.tsx
new file mode 100644
index 00000000..f38bb9dc
--- /dev/null
+++ b/lib/items-tech/table/hull/item-excel-template.tsx
@@ -0,0 +1,125 @@
+import * as ExcelJS from 'exceljs';
+import { saveAs } from "file-saver";
+
+// 해양 HULL 기능(공종) 유형
+const HULL_WORK_TYPES = ["HA", "HE", "HH", "HM", "NC"] as const;
+
+/**
+ * 해양 HULL 아이템 데이터 가져오기를 위한 Excel 템플릿 파일 생성 및 다운로드
+ */
+export async function exportHullItemTemplate() {
+ // 워크북 생성
+ const workbook = new ExcelJS.Workbook();
+ workbook.creator = 'Offshore HULL Item Management System';
+ workbook.created = new Date();
+
+ // 워크시트 생성
+ const worksheet = workbook.addWorksheet('해양 HULL 아이템');
+
+ // 컬럼 헤더 정의 및 스타일 적용
+ worksheet.columns = [
+ { header: '아이템 코드', key: 'itemCode', width: 15 },
+ { header: '아이템 명', key: 'itemName', width: 30 },
+ { header: '기능(공종)', key: 'workType', width: 15 },
+ { header: '설명', key: 'description', width: 50 },
+ { header: '항목1', key: 'itemList1', width: 20 },
+ { header: '항목2', key: 'itemList2', width: 20 },
+ { header: '항목3', key: 'itemList3', width: 20 },
+ { header: '항목4', key: 'itemList4', width: 20 },
+ ];
+
+ // 헤더 스타일 적용
+ 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 = [
+ {
+ itemCode: 'HULL001',
+ itemName: 'HULL 샘플 아이템 1',
+ workType: 'HA',
+ description: '이것은 해양 HULL 샘플 아이템 1의 설명입니다.',
+ itemList1: '항목1 샘플 데이터',
+ itemList2: '항목2 샘플 데이터',
+ itemList3: '항목3 샘플 데이터',
+ itemList4: '항목4 샘플 데이터'
+ },
+ {
+ itemCode: 'HULL002',
+ itemName: 'HULL 샘플 아이템 2',
+ workType: 'HE',
+ description: '이것은 해양 HULL 샘플 아이템 2의 설명입니다.',
+ itemList1: '항목1 샘플 데이터',
+ itemList2: '항목2 샘플 데이터',
+ itemList3: '',
+ itemList4: ''
+ }
+ ];
+
+ // 데이터 행 추가
+ 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(['공종 유형 안내: ' + HULL_WORK_TYPES.join(', ')]);
+ infoRow.font = { bold: true, color: { argb: 'FF0000FF' } };
+ worksheet.mergeCells(`A${infoRow.number}:H${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, 'offshore-hull-item-template.xlsx');
+ return true;
+ } catch (error) {
+ console.error('Excel 템플릿 생성 오류:', error);
+ throw error;
+ }
+}