AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.04k stars 659 forks source link

Cannot read property 'write' of undefined #384

Closed mathiasrw closed 8 years ago

mathiasrw commented 9 years ago

I suggest if xslx.core is not present when SELECT INTO XSLX() is called we display a more meaningful error message in the console instead of:

TypeError: Cannot read property 'write' of undefined
    at saveWorkbook (http://alasql.org/console/alasql.min.js:9:15277)
    at doExport (http://alasql.org/console/alasql.min.js:9:13590)
    at Object.alasql.into.XLSX (http://alasql.org/console/alasql.min.js:9:13337)
johnmichaelrivera commented 8 years ago

Hi!! I've got the same issue there...

I'm using SELECT INTO XLSX() Do you know the solution?Thanks

TypeError: Cannot read property 'write' of undefined at saveWorkbook (http://localhost/start/dashboard/js/libraries/alasql.min.js:10:11230) at doExport (http://localhost/start/dashboard/js/libraries/alasql.min.js:10:9543) at Object.alasql.into.XLSX (http://localhost/start/dashboard/js/libraries/alasql.min.js:10:9290) at eval [as intoallfn](eval at %28http://localhost/start/dashboard/js/libraries/alasql.min.js:6:8390%29, :3:33) at queryfn3 (http://localhost/start/dashboard/js/libraries/alasql.min.js:5:28698) at queryfn2 (http://localhost/start/dashboard/js/libraries/alasql.min.js:5:24797) at Object.eval [as datafn](eval at %28http://localhost/start/dashboard/js/libraries/alasql.min.js:6:14596%29, :3:57) at http://localhost/start/dashboard/js/libraries/alasql.min.js:5:24144 at Array.forEach (native) at queryfn (http://localhost/start/dashboard/js/libraries/alasql.min.js:5:24082)

mathiasrw commented 8 years ago

You need to include xlsx.js

http://alasql.org/console/xlsx.core.min.js

johnmichaelrivera commented 8 years ago

Thanks!!! Now I can download it as excel file but no data displaying. I console the result and it returns (an empty string)

mathiasrw commented 8 years ago

It gets more easy to help you if you provide example code

johnmichaelrivera commented 8 years ago

Can you help me about my problem? I want to export the table as excel wherein i just need to export three fields. The two fields are fixed data from table and One fields is from databse.

For my html table codes:

Monthly Cut off

FROM space space space TO

{{from |date:'MM-dd-yyyy'}}

-

{{to |date:'MM-dd-yyyy'}}


Employee's Name CashCard E-Money Card Account# Salary
{{item.fullname}} 0037 {{item.ecardacctno}}
No Data
{{CompanyList}}
JS controller: $scope.ExportToExcel = function(keyword){ ``` if($scope.CompanyList.length > 0){ $scope.exportLoading = true; toastr.info('Generating report, this might take a while. Thank you for your patience!'); var filename = "Payroll_Transactions_"+GetCurrentDate()+".xlsx"; CompanyFactory.ExportAll().success(function(result){ //export console.log(result); //Export only e money card account number and the data in UI following fields: CashCard and salary and compute with total amount // if(!keyword){ var a = alasql("SELECT [ecardacctno] INTO XLSX('"+filename+"', {headers:false}) FROM ? ORDER BY lname ASC", [result]); console.log(result); }else{ var a = alasql('SELECT [ecardacctno] AS ACCOUNTNUMBER INTO XLSX("'+filename+'", {headers:false}) FROM ? WHERE [lname] = "'+keyword+'" ORDER BY LASTNAME ASC', [result]); } if(a == 1){ $scope.exportLoading = false; toastr.success('Data exported!'); angular.element('#excelModal').modal('hide'); }else{ $scope.exportLoading = false; toastr.error('Error exporting data.'); } }) }else{ toastr.warning('Please wait while the application is loading the records.'); } } ```
johnmichaelrivera commented 8 years ago

As you can see the fixed data in my table is the cashcard field, the salary field which is blank,i will input some amount there and i'd like to export it to excel.The fields i'm going to export only are cashcard,E-money account and salary thanks

mathiasrw commented 8 years ago

so - you have a table with many fields, but you only want to work with a few of them - is that correct?

Are all data in one HTML table?

mathiasrw commented 8 years ago

@johnmichaelrivera Any news on this?

mathiasrw commented 8 years ago

@johnmichaelrivera Any news on this?

mathiasrw commented 8 years ago

Closing due to inactivity. Please reopen if needed.