I have an Excel sheet like this.
| Name | Phone Number | Address | |
|---|---|---|---|
| A | abc | 001 | USA |
| B | abf | 002 | CAN |
| C | abe | 003 | CHI |
| D | abd | 004 | UK |
And a Dropdown list on an HTML page like this
- Name
- Address
What I want when a user clicks on any of the items in the list box e.g on the Name Only The values from the name column should be fetched and converted into the JSON object.
I have tried this solution but I don't know how to specify the column name in the code.
var selectedFile;
document
.getElementById("fileUpload")
.addEventListener("change", function (event) {
selectedFile = event.target.files[0];
});
document
.getElementById("uploadExcel")
.addEventListener("click", function () {
if (selectedFile) {
var fileReader = new FileReader();
fileReader.onload = function (event) {
var data = event.target.result;
var workbook = XLSX.read(data, {
type: "binary"
});
workbook.SheetNames.forEach(sheet => {
let rowObject = XLSX.utils.sheet_to_row_object_array(
workbook.Sheets[sheet]
);
let jsonObject = JSON.stringify(rowObject);
document.getElementById("jsonData").innerHTML = jsonObject;
console.log(jsonObject);
});
};
fileReader.readAsBinaryString(selectedFile);
}
});
I am a newbie to javascript, so any help would be appreciated. Please only mention the javascript solutions. Thanks in advance.