Skip to content

Instantly share code, notes, and snippets.

@intelguasoft
Created May 28, 2019 21:55
Show Gist options
  • Save intelguasoft/3ef08c580585d068979b6c8f1298e69c to your computer and use it in GitHub Desktop.
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>.
/**
* 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