// 파일3개 방식: 각 담당자 파일에서 실행. 외부 파일을 직접 열지 않습니다. function main(workbook: ExcelScript.Workbook, ownerCode: string): string { return JSON.stringify(readInput(workbook, "tblInput", ownerCode, "입력")); } type Cell = string | number | boolean; interface Batch { owner: string; rows: Cell[][]; } const OWNERS = ["P01", "P02", "P03"]; const HEADERS = ["업무ID", "기준일", "담당자코드", "업무명", "금액"]; // 이 예제의 설계 한도입니다. Microsoft 제품 한도를 뜻하지 않습니다. const PER_SOURCE_LIMIT = 500; const TOTAL_LIMIT = 1500; function validateRows(rows: Cell[][], owner: string): Cell[][] { if (OWNERS.indexOf(owner) < 0) throw new Error("미등록 담당자: " + owner); if (!Array.isArray(rows) || rows.length > PER_SOURCE_LIMIT) throw new Error("원본 행 수/구조 확인: " + owner); const seen: string[] = []; const output: Cell[][] = []; for (const row of rows) { if (!Array.isArray(row) || row.length !== HEADERS.length) throw new Error("열 개수 오류: " + owner); if (row.every(v => v === "")) continue; if (typeof row[0] !== "string" || !new RegExp("^" + owner + "-[0-9]{4}$").test(row[0])) throw new Error("업무ID는 " + owner + "-0001 형식이어야 합니다."); if (seen.indexOf(row[0]) >= 0) throw new Error("중복 업무ID: " + row[0]); seen.push(row[0]); // 날짜는 Excel 일련번호가 아닌, 텍스트 YYYY-MM-DD로 통일합니다. if (typeof row[1] !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(row[1])) throw new Error("기준일 텍스트 형식 오류: " + row[0]); const parsed = new Date(row[1] + "T00:00:00Z"); if (isNaN(parsed.getTime()) || parsed.toISOString().slice(0, 10) !== row[1]) throw new Error("존재하지 않는 날짜: " + row[0]); if (row[2] !== owner) throw new Error("담당자코드 불일치: " + row[0]); if (typeof row[3] !== "string" || !row[3].trim() || row[3].length > 200 || /^[=+@\-\t\r]/.test(row[3].trim())) throw new Error("업무명 확인: " + row[0]); if (typeof row[4] !== "number" || !Number.isSafeInteger(row[4]) || Math.abs(row[4]) > 1000000000) throw new Error("금액은 절댓값10억 이하 정수: " + row[0]); output.push([row[0], row[1], row[2], row[3].trim(), row[4]]); } return output; } function readInput(workbook: ExcelScript.Workbook, name: string, owner: string, expectedSheet: string): Batch { const table = workbook.getTable(name); if (!table) throw new Error("입력 표 없음: " + name); if (table.getWorksheet().getName() !== expectedSheet) throw new Error("입력 시트가 다릅니다: " + name); const headers = table.getHeaderRowRange().getValues()[0]; if (JSON.stringify(headers) !== JSON.stringify(HEADERS)) throw new Error("머리글/열 순서 불일치: " + name); if (table.getRowCount() > PER_SOURCE_LIMIT) throw new Error("원본 표500행 초과: " + name); const values: Cell[][] = table.getRowCount() ? table.getRangeBetweenHeaderAndTotal().getValues() : []; return {owner, rows: validateRows(values, owner)}; }