I have been working on the upload page for text files, now I would like to upload excel files as well. My current code give me weird output. I assume something is wrong since my function was built for text files and now I have to modify something to read excel files. Here is my file reader code:
function fileSubmit(){
var fileExist = $('#fileUpload')[0];
var fileName = $('#fileUpload').val().split('\\').pop();
if(fileName && fileExist){
var reader = new FileReader();
var file = fileExist.files[0];
reader.onload = function(e) {
var text = reader.result.split(/\r\n|\n/);
var columnNames = text.shift().split('\t');
alert(columnNames);
}
reader.readAsText(file, 'UTF-8');
}
}
My alert output looks like this:
PK!b�h^�[Content_Types].xml �(����N�0E�H�C�-Jܲ@5��*Q>�ēƪc[�ii����B�j7���{2��h�nm���ƻR����U^7/���%��rZY�@1__�f��q��R4D�AJ�h>����V�ƹ�Z�9����NV�8ʩ����ji){^��-
I want to output my columns names because I have to do the validation for each row in the file. What is the best way to get this to work for .xsl
and .xsls
files? I found many examples with xls and xlxs javascript libraries but none of them worked when I tried to implement for many reason. I'm wondering is there anything that is supported in all browsers or this is something that should not be done in JavaScript? Thank you.