summaryrefslogtreecommitdiff
path: root/components/form-data/export-excel-form.tsx
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-06-01 13:52:21 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-06-01 13:52:21 +0000
commitbac0228d21b7195065e9cddcc327ae33659c7bcc (patch)
tree8f3016ae4533c8706d0c00a605d9b1d41968c2bc /components/form-data/export-excel-form.tsx
parent2fdce8d7a57c792bba0ac36fa554dca9c9cc31e3 (diff)
(대표님) 20250601까지 작업사항
Diffstat (limited to 'components/form-data/export-excel-form.tsx')
-rw-r--r--components/form-data/export-excel-form.tsx97
1 files changed, 85 insertions, 12 deletions
diff --git a/components/form-data/export-excel-form.tsx b/components/form-data/export-excel-form.tsx
index c4010df2..d0ccf980 100644
--- a/components/form-data/export-excel-form.tsx
+++ b/components/form-data/export-excel-form.tsx
@@ -12,6 +12,7 @@ export interface DataTableColumnJSON {
label: string;
type: ColumnType;
options?: string[];
+ shi?: boolean; // SHI-only field indicator
// Add any other properties that might be in columnsJSON
}
@@ -98,29 +99,64 @@ export async function exportExcelData({
const headerRow = worksheet.getRow(1);
headerRow.font = { bold: true };
headerRow.alignment = { horizontal: "center" };
- headerRow.eachCell((cell) => {
- cell.fill = {
- type: "pattern",
- pattern: "solid",
- fgColor: { argb: "FFCCCCCC" },
- };
+
+ // 각 헤더 셀에 스타일 적용
+ headerRow.eachCell((cell, colNumber) => {
+ const columnIndex = colNumber - 1;
+ const column = columnsJSON[columnIndex];
+
+ if (column?.shi === true) {
+ // SHI-only 필드는 더 진한 음영으로 표시 (헤더 라벨은 원본 유지)
+ cell.fill = {
+ type: "pattern",
+ pattern: "solid",
+ fgColor: { argb: "FFFF9999" }, // 연한 빨간색 배경
+ };
+ cell.font = { bold: true, color: { argb: "FF800000" } }; // 진한 빨간색 글자
+ } else {
+ // 일반 필드는 기존 스타일
+ cell.fill = {
+ type: "pattern",
+ pattern: "solid",
+ fgColor: { argb: "FFCCCCCC" }, // 연한 회색 배경
+ };
+ }
});
// 3. 데이터 행 추가
- tableData.forEach((row) => {
+ tableData.forEach((rowData, rowIndex) => {
const rowValues = columnsJSON.map((col) => {
- const value = row[col.key];
+ const value = rowData[col.key];
return value !== undefined && value !== null ? value : "";
});
- worksheet.addRow(rowValues);
+ const dataRow = worksheet.addRow(rowValues);
+
+ // SHI-only 컬럼의 데이터 셀에도 음영 적용
+ dataRow.eachCell((cell, colNumber) => {
+ const columnIndex = colNumber - 1;
+ const column = columnsJSON[columnIndex];
+
+ if (column?.shi === true) {
+ // SHI-only 필드의 데이터 셀에 연한 음영 적용
+ cell.fill = {
+ type: "pattern",
+ pattern: "solid",
+ fgColor: { argb: "FFFFCCCC" }, // 매우 연한 빨간색 배경
+ };
+ // 읽기 전용임을 나타내기 위해 이탤릭 적용
+ cell.font = { italic: true, color: { argb: "FF666666" } };
+ }
+ });
});
// 4. 데이터 유효성 검사 적용
const maxRows = 5000; // 데이터 유효성 검사를 적용할 최대 행 수
columnsJSON.forEach((col, idx) => {
- if (col.type === "LIST" && validationRanges.has(col.key)) {
- const colLetter = worksheet.getColumn(idx + 1).letter;
+ const colLetter = worksheet.getColumn(idx + 1).letter;
+
+ // SHI-only 필드가 아닌 LIST 타입에만 유효성 검사 적용
+ if (col.type === "LIST" && validationRanges.has(col.key) && col.shi !== true) {
const validationRange = validationRanges.get(col.key)!;
// 유효성 검사 정의
@@ -156,6 +192,19 @@ export async function exportExcelData({
}
}
}
+
+ // SHI-only 필드의 빈 행들에도 음영 처리 적용
+ if (col.shi === true) {
+ for (let rowIdx = tableData.length + 2; rowIdx <= maxRows; rowIdx++) {
+ const cell = worksheet.getCell(`${colLetter}${rowIdx}`);
+ cell.fill = {
+ type: "pattern",
+ pattern: "solid",
+ fgColor: { argb: "FFFFCCCC" },
+ };
+ cell.font = { italic: true, color: { argb: "FF666666" } };
+ }
+ }
});
// 5. 컬럼 너비 자동 조정
@@ -178,7 +227,31 @@ export async function exportExcelData({
column.width = Math.min(Math.max(maxLength + 2, 10), 50);
});
- // 6. 파일 다운로드
+ // 6. 범례 추가 (별도 시트)
+ const legendSheet = workbook.addWorksheet("Legend");
+ legendSheet.addRow(["Excel Template Legend"]);
+ legendSheet.addRow([]);
+ legendSheet.addRow(["Symbol", "Description"]);
+ legendSheet.addRow(["Red background header", "SHI-only fields that cannot be edited"]);
+ legendSheet.addRow(["Gray background header", "Regular editable fields"]);
+ legendSheet.addRow(["Light red background cells", "Data in SHI-only fields (read-only)"]);
+ legendSheet.addRow(["Red text color", "SHI-only field headers"]);
+
+ // 범례 스타일 적용
+ const legendHeaderRow = legendSheet.getRow(1);
+ legendHeaderRow.font = { bold: true, size: 14 };
+
+ const legendTableHeader = legendSheet.getRow(3);
+ legendTableHeader.font = { bold: true };
+ legendTableHeader.eachCell((cell) => {
+ cell.fill = {
+ type: "pattern",
+ pattern: "solid",
+ fgColor: { argb: "FFCCCCCC" },
+ };
+ });
+
+ // 7. 파일 다운로드
const buffer = await workbook.xlsx.writeBuffer();
saveAs(
new Blob([buffer]),