Alasql: I am trying to read a excel file but I am getting Invalid HTML: could not find <table> issue

Created on 8 Jun 2018  路  7Comments  路  Source: agershun/alasql

Hi All,

I am reading an excel file using below code

if (event.fromElement.files.length==0) {
            return(false);   // leave in case no file was chosen
        };
        alasql('SELECT * FROM FILE(?,{headers:true})', [event], function (data) {
            $rootScope.eData = data;     //  eData contains the JSON representation of the Excel sheet rows
        }); 

and the html code is as follows:

<input type="file" ng-mouseleave="loadFile($event)" />

On observing the browser console the issue is

xlsx.full.min.js:21 Uncaught Error: Invalid HTML: could not find <table>
    at e (xlsx.full.min.js:21)
    at Object.r [as to_workbook] (xlsx.full.min.js:21)
    at Pp (xlsx.full.min.js:19)
    at Np (xlsx.full.min.js:19)
    at Object.dg [as read] (xlsx.full.min.js:22)
    at alasql.min.js:2
    at XMLHttpRequest.a.onload (alasql.min.js:11)`

Thanks in advance!!!

! Question

All 7 comments

Any chance you can make an example on jsfiddle?

Any news on this?

Hi.. I am new to JSFiddle so tried to create a JSFiddle but faced issues so couldn't make it.

If you can make a html with the example code that is also cool (add it to this issue by dragging it into the text box where you write text)

@mathiasrw i am having same problem, can you please help me out, here is my code
// url is link of google sheet -> https://docs.google.com/spreadsheets/d/1Xr2IjT8Ohh3fYqoAKIMLiR21AleNMNJ9SXVlkLIn2F4/edit?usp=sharing

fetch (url)
    .then(response => {
      const reader = response.body.getReader();
      reader.read()
      .then(({value}) => {
        try {
          var workbook = XLSX.read(value, {type:'array'});
        } catch (error) {
          setErrorMessage(error.message);
          return;
        }
        console.log(workbook);
        var sheetName = workbook.SheetNames;
        console.log(XLSX.utils.sheet_to_json(workbook.Sheets[sheetName[0]],{raw: true, defval:null}));
      });
    });

@gursimran-agile

I have a feeling you could do the same with something like

alasql.promise('select * from xlsx("https://docs.google.com/spreadsheets/d/1Xr2IjT8Ohh3fYqoAKIMLiR21AleNMNJ9SXVlkLIn2F4/edit?usp=sharing",{sheetid:?})', sheetName[0])

But to be fair there is actually a plugin only to read data from google spreadsheet. Please have a look at https://github.com/agershun/alasql/wiki/TABLETOP - in the example its loaded directly to a html table, but could just a well be used to load into a DB table (or read out directly).

thanks a lot @mathiasrw , reading the links provided by works for me,
I published my spreadSheet, now it works fine(with the same code). Thanks a lot once again :+1: :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SWard1992 picture SWard1992  路  3Comments

umasudhan picture umasudhan  路  4Comments

songokudbz picture songokudbz  路  5Comments

mathiasrw picture mathiasrw  路  5Comments

DickSwart picture DickSwart  路  6Comments