Add validation for uploaded file data format
This commit is contained in:
15
src/App.jsx
15
src/App.jsx
@@ -29,6 +29,21 @@ function App() {
|
|||||||
const sheetName = workbook.SheetNames[0];
|
const sheetName = workbook.SheetNames[0];
|
||||||
const worksheet = workbook.Sheets[sheetName];
|
const worksheet = workbook.Sheets[sheetName];
|
||||||
const jsonData = utils.sheet_to_json(worksheet, {raw:true});
|
const jsonData = utils.sheet_to_json(worksheet, {raw:true});
|
||||||
|
|
||||||
|
if (jsonData.length === 0) {
|
||||||
|
alert("파일에 데이터가 없습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns = Object.keys(jsonData[0]);
|
||||||
|
const requiredColumns = ['address', 'amount'];
|
||||||
|
|
||||||
|
if (columns.length !== 2 ||
|
||||||
|
!requiredColumns.every(col => columns.includes(col))) {
|
||||||
|
alert("양식이 맞지 않습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let total = totalAmount;
|
let total = totalAmount;
|
||||||
|
|
||||||
const filteredData = jsonData.filter(row => {
|
const filteredData = jsonData.filter(row => {
|
||||||
|
|||||||
Reference in New Issue
Block a user