Created
May 28, 2019 21:55
-
-
Save intelguasoft/3ef08c580585d068979b6c8f1298e69c to your computer and use it in GitHub Desktop.
Metodo para obtener las hojas de un archivo de Excel y cargarlas en un elemento <select>.
This file contains 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
/** | |
* Metodo para obtener las hojas de un archivo de Excel y cargarlas en un elemento <select>. | |
* Se utilizo la librería SheetJS para este ejemplo. | |
* Henry Díaz, <hnrdiaz@gmail.com> | |
**/ | |
$('#input-excel').change(function(e) { | |
var reader = new FileReader(); | |
let sheetNames; | |
reader.readAsArrayBuffer(e.target.files[0]); | |
reader.onload = function(e) { | |
var data = new Uint8Array(reader.result); | |
var wb = XLSX.read(data, { | |
type: 'array' | |
}); | |
$('#hoja-excel').empty(); | |
sheetNames = wb.SheetNames; | |
$('#hoja-excel').append(`<option value="">[Seleccione una hoja...]</option>`); | |
sheetNames.forEach(function(element) { | |
$('#hoja-excel').append(`<option value="${element}">${element}</option>`); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment