Created
May 28, 2019 21:57
-
-
Save intelguasoft/bf95735685d6b37ee74629d45c4d027a to your computer and use it in GitHub Desktop.
Metodo para asignar la data de una determinada de un archivo de Excel y cargarlas en un elemento del documento actual.
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
/** | |
* Metodo para asignar la data de una determinada de un archivo de Excel y cargarlas en un elemento del documento actual. | |
* Se utilizo la librería SheetJS para este ejemplo. | |
* Henry Díaz, <[email protected]> | |
**/ | |
$('#hoja-excel').change(function(e) { | |
let hoja = e.target.value; | |
console.log(e); | |
// console.log($('#input-excel')[0].files); | |
// $('#datos')[0].innerHTML.empty(); | |
let reader = new FileReader(); | |
reader.readAsArrayBuffer($('#input-excel')[0].files[0]); | |
reader.onload = function(e) { | |
var data = new Uint8Array(reader.result); | |
var wb = XLSX.read(data, { | |
type: 'array' | |
}); | |
var worksheet = wb.Sheets[hoja]; | |
console.log(XLSX.utils.sheet_to_json(worksheet, { | |
// header: 1, | |
raw: true | |
})); | |
var htmlstr = XLSX.write(wb, { | |
sheet: hoja, | |
type: 'binary', | |
bookType: 'html' | |
}); | |
$('#datos')[0].innerHTML = htmlstr; | |
$('#datos table').addClass('table table-striped table-sm table-bordered'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment