Skip to content

Instantly share code, notes, and snippets.

@gogl92
Created March 21, 2018 05:17
Show Gist options
  • Save gogl92/ae911e06aa2c3e8f8af7c4a43a5e0706 to your computer and use it in GitHub Desktop.
Save gogl92/ae911e06aa2c3e8f8af7c4a43a5e0706 to your computer and use it in GitHub Desktop.
Read and Show a File with Javascript in Yii2
<?php
$this->registerJsFile('https://unpkg.com/xlsx/dist/xlsx.full.min.js');
$this->registerJs('$(\'#input-excel\').change(function(e){
var reader = new FileReader();
reader.readAsArrayBuffer(e.target.files[0]);
reader.onload = function(e) {
var data = new Uint8Array(reader.result);
var wb = XLSX.read(data,{type:\'array\'});
var htmlstr = XLSX.write(wb,{sheet:"Ejemplo Semanal", type:\'binary\',bookType:\'html\'});
$(\'#wrapper\')[0].innerHTML += htmlstr;
}
});')
?>
<div id="wrapper">
<input type="file" id="input-excel" />
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment