1

I am trying to import CSV and get the result in an array. I am following this jsfiddle

print('AlaSQL v'+alasql.version)
print('Please upload txt, json, csv, tsv, tab, xlsx, xls or html file to see the content')

loadFile = function(event) {
 alasql('SELECT * FROM FILE(?,{headers:true})',[event],function(data){
  print(data)
 });
}

function print(x){
    document.getElementById('output').textContent += JSON.stringify(x,  null, '\t')+"\n";
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.full.min.js"></script>

<script src="https://rawgit.com/agershun/alasql/develop/dist/alasql.js"></script>
<input id="readfile" type="file" onchange="loadFile(event)"/>
<xmp id="output"></xmp>

When I am trying to use the same in angular 2, I am getting the following error

Error: Wrong usage of FILE() function

I have installed alasql npm package, following is my home.html and home.ts code:

home.html

<input id="readfile" type="file" (change)="loadFile(event)"/>

home.ts

  loadFile = function(event) {
    alasql('SELECT * FROM FILE(?,{headers:true})',[event],function(data){
       console.log(data,"data");
     });
}

When I select and upload the file, I am getting that error, for reference see below screenshot:

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Kirandeep Kaur
  • 179
  • 2
  • 18

0 Answers0