diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-06-13 07:08:01 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-06-13 07:08:01 +0000 |
| commit | c72d0897f7b37843109c86f61d97eba05ba3ca0d (patch) | |
| tree | 887dd877f3f8beafa92b4d9a7b16c84b4a5795d8 /lib/welding/table/exporft-ocr-data.ts | |
| parent | ff902243a658067fae858a615c0629aa2e0a4837 (diff) | |
(대표님) 20250613 16시 08분 b-rfq, document 등
Diffstat (limited to 'lib/welding/table/exporft-ocr-data.ts')
| -rw-r--r-- | lib/welding/table/exporft-ocr-data.ts | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/lib/welding/table/exporft-ocr-data.ts b/lib/welding/table/exporft-ocr-data.ts new file mode 100644 index 00000000..76856808 --- /dev/null +++ b/lib/welding/table/exporft-ocr-data.ts @@ -0,0 +1,90 @@ +// lib/export-ocr-data.ts +import ExcelJS from "exceljs" +import type { OcrRow } from "@/db/schema" + +/** + * OCR 데이터를 엑셀로 내보내는 단순한 함수 + */ +export async function exportOcrDataToExcel( + data: OcrRow[], + filename: string = "OCR Data" +): Promise<void> { + if (!data || data.length === 0) { + throw new Error("No data to export") + } + + // 워크북 생성 + const workbook = new ExcelJS.Workbook() + const worksheet = workbook.addWorksheet("OCR Data") + + // 컬럼 정의 (OCR 데이터에 맞게 설정) + const columns = [ + { key: "reportNo", header: "Report No", width: 15 }, + { key: "no", header: "No", width: 10 }, + { key: "identificationNo", header: "Identification No", width: 20 }, + { key: "tagNo", header: "Tag No", width: 15 }, + { key: "jointNo", header: "Joint No", width: 15 }, + { key: "jointType", header: "Joint Type", width: 15 }, + { key: "weldingDate", header: "Welding Date", width: 15 }, + { key: "confidence", header: "confidence", width: 15 }, + { key: "userName", header: "사용자 이름", width: 15 }, + { key: "userEmail", header: "사용자 이메일", width: 15 }, + { key: "createdAt", header: "생성일", width: 20 }, + // 필요한 다른 컬럼들도 추가 가능 + ] + + // 워크시트에 컬럼 설정 + worksheet.columns = columns + + // 헤더 스타일 설정 + const headerRow = worksheet.getRow(1) + headerRow.font = { bold: true } + headerRow.alignment = { horizontal: "center" } + headerRow.fill = { + type: "pattern", + pattern: "solid", + fgColor: { argb: "FFCCCCCC" }, + } + + // 데이터 추가 + data.forEach((row) => { + worksheet.addRow({ + reportNo: row.reportNo || "", + no: row.no || "", + identificationNo: row.identificationNo || "", + tagNo: row.tagNo || "", + jointNo: row.jointNo || "", + jointType: row.jointType || "", + confidence: row.confidence || "", + weldingDate: row.weldingDate ? new Date(row.weldingDate).toLocaleDateString() : "", + userName: row.userName || "", + userEmail: row.userEmail || "", + + createdAt: row.createdAt ? new Date(row.createdAt).toLocaleString() : "", + }) + }) + + // 모든 행에 테두리 추가 + worksheet.eachRow((row, rowNumber) => { + row.eachCell((cell) => { + cell.border = { + top: { style: "thin" }, + left: { style: "thin" }, + bottom: { style: "thin" }, + right: { style: "thin" }, + } + }) + }) + + // 파일 다운로드 + const buffer = await workbook.xlsx.writeBuffer() + const blob = new Blob([buffer], { + type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + }) + const url = URL.createObjectURL(blob) + const link = document.createElement("a") + link.href = url + link.download = `${filename}.xlsx` + link.click() + URL.revokeObjectURL(url) +}
\ No newline at end of file |
