JAVASCRIPT only please.
- Turning Excel file into JSON data
let selectedFile;
// Uploading file
const inputEl = document.getElementById("input");
inputEl.addEventListener("change", function (e) {
e.preventDefault();
selectedFile = e.target.files[0];
});
// BTN
const btnEl = document.querySelector("button");
btnEl.addEventListener("click", function () {
if (selectedFile) {
let fileReader = new FileReader();
fileReader.readAsBinaryString(selectedFile);
fileReader.onload = function (event) {
// console.log(event.target.result);
let data = event.target.result;
let workbook = XLSX.read(data, { type: "binary" });
workbook.SheetNames.forEach((sheet) => {
let rowObject = XLSX.utils.sheet_to_row_object_array(
workbook.Sheets[sheet]
);
// console.log(rowObject);
document.getElementById("jsondata").innerHTML = JSON.stringify(
rowObject,
undefined,
4
);
});
};
}
});
I get this results after uploading the excel file and clicking in the convert button: json data after converting the excel file
How to save that json data into data.json file in VS code like the example below in the SS I just copy and pasted the json data from the results inside the data.json so I can fetch the data
The main goal is to fetch the JSON data obtained after clicking the covert button