alasql需要已经包含的xlsx [英] alasql requires xlsx which is already included

查看:313
本文介绍了alasql需要已经包含的xlsx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 alasql xlsx 将数据导出到excel工作表。我在这里遵循了所有准则: https://github.com/agershun/alasql/wiki/ Xlsx

I am trying to export data to an excel sheet using alasql and xlsx. I have followed all the guidelines here: https://github.com/agershun/alasql/wiki/Xlsx

这是我的功能:

exportToExcel(data: any) {
   console.log(XLSX.version);

   alasql
     .promise('SELECT * INTO XLSX("test.csv",{headers:true}) FROM ?', [data])
     .then(function (data) { console.log(data); })
     .catch(function (err) { console.log('Error:', err); });;
}

这使我在控制台中遇到此错误以及 XLSX 版本:

which gives me this error in my console together with the XLSX version:

VM9931 main.bundle.js:1044 0.12.4
VM9931 main。 bundle.js:1047错误:错误:请在B(VM9930 vendor.bundle.js:6298)在Object.A.into.XLSX(VM9930 vendor.bundle)中包含xlsx.js库
。 js:6303)

我遇到的问题是我已经包含了 XLSX 库,并且可以正常运行(记录的版本为 0.12.4 )。如果我将 XLSX( test.csv)... 更改为 CSV( test.csv)... 可以完美导出到CSV。

The problem I am experiencing is that I have already included the XLSX library and it's working correctly (the version logged is 0.12.4). If I change the XLSX("test.csv")... to CSV("test.csv")... it exports to CSV perfectly.

推荐答案

从alasql中读取代码后,我发现:

After reading the code from alasql, I found that :

var getXLSX = function() {
  var XLSX = alasql["private"].externalXlsxLib;

  if (XLSX) {
    return XLSX;
  }

  if (utils.isNode || utils.isBrowserify || utils.isMeteorServer) {
    /*not-for-browser/*
    XLSX = require('xlsx') || null;
    //*/
  } else {
    XLSX = utils.global.XLSX || null;
  }

  if (null === XLSX) {
    throw new Error('Please include the xlsx.js library');
  }

  return XLSX;
};

我不知道为什么,但是 XLSX = require('xlsx') || null; 被注释,因此我将externalXlsxLib设置为使用xlsx:

I don't know why but XLSX = require('xlsx') || null; is commented so I've set externalXlsxLib to use xlsx :

import * as alasql from 'alasql';
alasql["private"].externalXlsxLib = require('xlsx');

对我有用

这篇关于alasql需要已经包含的xlsx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆