Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeben committed Dec 11, 2023
1 parent f7bf489 commit 22d6fb2
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,11 @@ function readFile(file, callback) {
const reader = new FileReader();
reader.onload = function(event) {
const data = event.target.result;
const workbook = XLSX.read(data, { type: 'binary' });

// 첫 번째 시트의 첫 행을 제거
const firstSheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[firstSheetName];
removeFirstRow(worksheet);

callback(workbook);
};
reader.readAsBinaryString(file);
}

function removeFirstRow(worksheet) {
const range = XLSX.utils.decode_range(worksheet['!ref']);
for (let R = range.s.r + 1; R <= range.e.r; ++R) {
for (let C = range.s.c; C <= range.e.c; ++C) {
const cellAddress = XLSX.utils.encode_cell({r: R, c: C});
const cellAboveAddress = XLSX.utils.encode_cell({r: R - 1, c: C});
worksheet[cellAboveAddress] = worksheet[cellAddress];
}
}
range.e.r--;
worksheet['!ref'] = XLSX.utils.encode_range(range);
}

function processFiles() {
if (!excel1 || !excel2) {
alert('두 개의 파일을 모두 업로드해주세요.');
Expand All @@ -54,13 +34,24 @@ function processFiles() {
const sheet1 = excel1.Sheets[excel1.SheetNames[0]];
const sheet2 = excel2.Sheets[excel2.SheetNames[0]];

const data1 = XLSX.utils.sheet_to_json(sheet1, { defval: "" });
const data2 = XLSX.utils.sheet_to_json(sheet2);
// 첫 행을 제외하고 데이터를 읽음
const data1 = XLSX.utils.sheet_to_json(sheet1, { defval: "", range: 1 });
const data2 = XLSX.utils.sheet_to_json(sheet2, { defval: "", range: 1 });

// 데이터 처리 로직...
// 예: 전화번호를 기반으로 매칭하고 송장번호 업데이트

const originalHeaders = Object.keys(XLSX.utils.sheet_to_json(sheet1, { header: 1 })[0]);
data1.forEach(row1 => {
const formattedPhone = String(row1['수취인연락처1']).replace(/-/g, '').trim();
const matchingRow = data2.find(row2 => String(row2['받는분전화번호']).trim() === formattedPhone);
if (matchingRow) {
row1['송장번호'] = matchingRow['운송장번호'];
} else {
row1['송장번호'] = row1['송장번호'] || "";
}
});

const originalHeaders = Object.keys(XLSX.utils.sheet_to_json(sheet1, { header: 1, range: 1 })[0]);
const updatedSheet = XLSX.utils.json_to_sheet(data1, {
header: originalHeaders,
skipHeader: true
Expand All @@ -69,6 +60,7 @@ function processFiles() {
XLSX.writeFile(excel1, 'updated_excel1.xlsx');
}


function updateProcessButtonVisibility() {
if (excel1 && excel2) {
document.getElementById('processButton').style.display = 'block';
Expand Down

0 comments on commit 22d6fb2

Please sign in to comment.