Last active
May 17, 2021 23:44
-
-
Save brunovcosta/e6626b9a8afa8e13cadca8f86d98ca38 to your computer and use it in GitHub Desktop.
Async read Excel file from browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SheetJS should be loaded (https://unpkg.com/xlsx/dist/xlsx.full.min.js) | |
new Promise((resolve, reject) => { | |
const fileInput = document.createElement("input") | |
fileInput.type='file' | |
fileInput.style.display='none' | |
fileInput.onchange=evt => { | |
const reader = new FileReader(); | |
reader.readAsBinaryString(evt.target.files[0]) | |
reader.onload = evt2 => { | |
const workbook = XLSX.read(evt2.target.result, {type: "binary"}) | |
console.log(workbook) | |
resolve(JSON.stringify(XLSX.utils.sheet_to_json(workbook.Sheets.Raw))) | |
} | |
} | |
document.body.appendChild(fileInput) | |
fileInput.click() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment