1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
import * as ExcelJS from 'exceljs';
import { saveAs } from "file-saver";
/**
* 아이템 데이터 가져오기를 위한 Excel 템플릿 파일 생성 및 다운로드
*/
export async function exportItemTemplate() {
// 워크북 생성
const workbook = new ExcelJS.Workbook();
workbook.creator = 'Item Management System';
workbook.created = new Date();
// 워크시트 생성
const worksheet = workbook.addWorksheet('아이템');
// 컬럼 헤더 정의 및 스타일 적용
worksheet.columns = [
{ header: '자재그룹코드', key: 'itemCode', width: 15 },
{ header: '자재그룹명', key: 'itemName', width: 30 },
{ header: '상세', key: 'description', width: 50 },
{ header: '부모 아이템 코드', key: 'parentItemCode', width: 18 },
{ header: '레벨', key: 'itemLevel', width: 10 },
{ header: '삭제 플래그', key: 'deleteFlag', width: 12 },
{ header: '단위', key: 'unitOfMeasure', width: 10 },
{ header: '강종', key: 'steelType', width: 10 },
{ header: '등급 재질', key: 'gradeMaterial', width: 20 },
{ header: '변경일자', key: 'changeDate', width: 12 },
{ header: '기본단위', key: 'baseUnitOfMeasure', width: 12 }
];
// 헤더 스타일 적용
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: 'SAMPLE001',
itemName: '샘플1',
description: '샘플1',
parentItemCode: null,
itemLevel: 1,
deleteFlag: 'N',
unitOfMeasure: 'EA',
steelType: 'SS',
gradeMaterial: 'gradeMaterial',
changeDate: '20241201',
baseUnitOfMeasure: 'EA'
},
{
itemCode: 'SAMPLE002',
itemName: '샘플2',
description: '샘플2',
parentItemCode: 'SAMPLE001',
itemLevel: 2,
deleteFlag: 'N',
unitOfMeasure: 'EA',
steelType: 'SS',
gradeMaterial: 'gradeMaterial',
changeDate: '20241201',
baseUnitOfMeasure: 'EA'
}
];
// 데이터 행 추가
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, 'item-template.xlsx');
return true;
} catch (error) {
console.error('Excel 템플릿 생성 오류:', error);
throw error;
}
}
|