Skip to content

Commit

Permalink
code : 구버전 엑셀 로직 완성
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimdonghyeon7645 committed Mar 3, 2024
1 parent f848d8c commit 01cd4f1
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 18 deletions.
46 changes: 37 additions & 9 deletions auto-excel/public/electron/edit_excel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
42 changes: 35 additions & 7 deletions auto-excel/public/electron/edit_excel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion auto-excel/src/components/BottomBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion auto-excel/src/components/InputBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => [
Expand Down

0 comments on commit 01cd4f1

Please sign in to comment.