From 01cd4f1b116aa4087ba6ec7b57f1611d1596ac8c Mon Sep 17 00:00:00 2001 From: Kimdonghyeon7645 Date: Sun, 3 Mar 2024 22:07:25 +0900 Subject: [PATCH] =?UTF-8?q?code=20:=20=EA=B5=AC=EB=B2=84=EC=A0=84=20?= =?UTF-8?q?=EC=97=91=EC=85=80=20=EB=A1=9C=EC=A7=81=20=EC=99=84=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto-excel/public/electron/edit_excel.js | 46 +++++++++++++++---- auto-excel/public/electron/edit_excel.ts | 42 ++++++++++++++--- auto-excel/src/components/BottomBox/index.tsx | 7 ++- auto-excel/src/components/InputBox/index.tsx | 1 - 4 files changed, 78 insertions(+), 18 deletions(-) diff --git a/auto-excel/public/electron/edit_excel.js b/auto-excel/public/electron/edit_excel.js index f1a61f5..573b69d 100644 --- a/auto-excel/public/electron/edit_excel.js +++ b/auto-excel/public/electron/edit_excel.js @@ -108,25 +108,53 @@ var editExcelNewMode = function (mainWindow, data) { var editExcelOldMode = function (mainWindow, data) { var newFilePath = data.path.replace(".xlsx", "_편집본.xlsx"); XlsxPopulate.fromFileAsync(data.path).then(function (workbook) { return __awaiter(void 0, void 0, void 0, function () { - var sheetCnt_1, cnt, error_2; + var sheetIdx_1, cnt_1, error_2; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); - console.log(data.data); - sheetCnt_1 = 0; - cnt = 0; + sheetIdx_1 = 0; + cnt_1 = 0; workbook.sheets().forEach(function (sheet) { - console.log("Sheet Name:", sheet.name()); - sheetCnt_1++; + var scanRowIdx = 60; + if (sheet.cell(scanRowIdx, 3).value() !== "□ 접속함 (체널별 전류)") { + // 표의 시작인덱스가 60이 아닐때 추가 처리 + console.log("[WARNING] 표 시작위치가 예상과 다르게 인식됨!"); + } + scanRowIdx++; + // 헤더 총 개수 구하기 (headerCnt) + var headerCnt = 0; + var scanColIdx = 9; + for (var loopCnt = 0; loopCnt < 100; loopCnt++) { + if (sheet.cell(scanRowIdx, scanColIdx).value() === undefined) + break; + scanColIdx += 2; + headerCnt++; + } + scanRowIdx++; + for (var loopCnt = 0; loopCnt < 100; loopCnt++) { + // console.log(sheet.cell(scanRowIdx, 3).value()); + if (sheet.cell(scanRowIdx, 3).value() === undefined) + break; + for (var colIdx = 0; colIdx < headerCnt; colIdx++) { + var targetValue = sheet.cell(scanRowIdx, 9 + colIdx * 2).value(); + if (targetValue === undefined) + continue; + var newValue = getRandomValue(data.data.values[sheetIdx_1][0], data.data.values[sheetIdx_1][1], data.data.deltaA); + sheet.cell(scanRowIdx, 9 + colIdx * 2).value(newValue); + cnt_1++; + } + scanRowIdx++; + } + sheetIdx_1++; }); return [4 /*yield*/, workbook.toFileAsync(newFilePath)]; case 1: _a.sent(); mainWindow.webContents.send("edit-excel-end", { - sheetCnt: sheetCnt_1, - rowCnt: "-", - cellCnt: cnt * 2 + sheetCnt: sheetIdx_1, + rowCnt: 0, + cellCnt: cnt_1 }); return [3 /*break*/, 3]; case 2: diff --git a/auto-excel/public/electron/edit_excel.ts b/auto-excel/public/electron/edit_excel.ts index 9ad1115..ae77c97 100644 --- a/auto-excel/public/electron/edit_excel.ts +++ b/auto-excel/public/electron/edit_excel.ts @@ -51,19 +51,47 @@ const editExcelOldMode = (mainWindow: BrowserWindow, data: { path: string; data: const newFilePath = data.path.replace(".xlsx", "_편집본.xlsx"); XlsxPopulate.fromFileAsync(data.path).then(async (workbook: any) => { try { - console.log(data.data); - let sheetCnt: number = 0; + let sheetIdx: number = 0; let cnt: number = 0; workbook.sheets().forEach((sheet: any) => { - console.log("Sheet Name:", sheet.name()); - sheetCnt++; + let scanRowIdx = 60; + if (sheet.cell(scanRowIdx, 3).value() !== "□ 접속함 (체널별 전류)") { + // 표의 시작인덱스가 60이 아닐때 추가 처리 + console.log("[WARNING] 표 시작위치가 예상과 다르게 인식됨!"); + } + scanRowIdx++; + + // 헤더 총 개수 구하기 (headerCnt) + let headerCnt = 0; + let scanColIdx = 9; + for (let loopCnt = 0; loopCnt < 100; loopCnt++) { + if (sheet.cell(scanRowIdx, scanColIdx).value() === undefined) break; + scanColIdx += 2; + headerCnt++; + } + scanRowIdx++; + + for (let loopCnt = 0; loopCnt < 100; loopCnt++) { + // console.log(sheet.cell(scanRowIdx, 3).value()); + if (sheet.cell(scanRowIdx, 3).value() === undefined) break; + for (let colIdx = 0; colIdx < headerCnt; colIdx++) { + const targetValue = sheet.cell(scanRowIdx, 9 + colIdx * 2).value(); + if (targetValue === undefined) continue; + const newValue = getRandomValue(data.data.values[sheetIdx][0], data.data.values[sheetIdx][1], data.data.deltaA); + sheet.cell(scanRowIdx, 9 + colIdx * 2).value(newValue); + cnt++; + } + scanRowIdx++; + } + + sheetIdx++; }); await workbook.toFileAsync(newFilePath); mainWindow.webContents.send("edit-excel-end", { - sheetCnt: sheetCnt, - rowCnt: "-", - cellCnt: cnt * 2, + sheetCnt: sheetIdx, + rowCnt: 0, + cellCnt: cnt, }); // showSuccessPopup(mainWindow, cnt); } catch (error) { diff --git a/auto-excel/src/components/BottomBox/index.tsx b/auto-excel/src/components/BottomBox/index.tsx index 1efd724..8cf56da 100644 --- a/auto-excel/src/components/BottomBox/index.tsx +++ b/auto-excel/src/components/BottomBox/index.tsx @@ -10,7 +10,12 @@ interface BottomBoxProps { const BottomBox = ({ mode, filePath, inputData }: BottomBoxProps) => { useEffect(() => { window.ipc.on("edit-excel-end", (data: any) => { - alert(`엑셀 작업이 정상적으로 완료되었습니다.\n변환한 행: ${data?.rowCnt}(개), 변환한 셀: ${data?.cellCnt}(개)`); + alert( + `엑셀 작업이 정상적으로 완료되었습니다.\n` + + (data?.sheetCnt !== 1 + ? `변환한 시트: ${data?.sheetCnt}(개), 변환한 셀: ${data?.cellCnt}(개)` + : `변환한 행: ${data?.rowCnt}(개), 변환한 셀: ${data?.cellCnt}(개)`) + ); }); return () => window.ipc.offAll("edit-excel-end"); // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/auto-excel/src/components/InputBox/index.tsx b/auto-excel/src/components/InputBox/index.tsx index 5bbbfa8..82739ca 100644 --- a/auto-excel/src/components/InputBox/index.tsx +++ b/auto-excel/src/components/InputBox/index.tsx @@ -24,7 +24,6 @@ const InputBox = ({ mode, inputData, setMode, setInputData }: InputBoxProps) => maxA: parseFloat((parseFloat(data.sheetValues[1]) + 0.2).toFixed(1)), })); } else if (data.mode === 1) { - console.log(data); setInputData((_data: any) => ({ ..._data, values: data.sheetValues.map((val: any) => [