JSFiddle - React, Tailwind, and code Playground
by velo_ninja
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Excel Data Cleaner</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
</head>
<body>
<h1>Excel Data Cleaner</h1>
<input type="file" id="fileInput" />
<button id="processButton">Process File</button>
<script>
document.getElementById('processButton').addEventListener('click', processFile);
function processFile() {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
if (!file) {
alert('Please upload an Excel file!');
return;
}
const reader = new FileReader();
reader.onload = (e) => {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array', cellDates: true });
const worksheet = workbook.Sheets[workbook.SheetNames[0]];
if (!worksheet) {
alert('No worksheet found!');
return;
}
const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
const cleanedData = cleanData(jsonData);
const dataObject = convertToDataObject(cleanedData);
console.log(dataObject);
};
reader.readAsArrayBuffer(file);
}
function cleanData(data) {
const uniqueEntries = new Map();
const header = data[0].map(col => col ? col.toString().trim() : col); // Trim header values
for (let i = 1; i < data.length; i++) {
const row = data[i].slice();
const processedRow = processRow(row);
const key = processedRow.join('|'); // Create a unique key for the row
if...