简体   繁体   English

如何使用ember.js上传XLSX文件并将其转换为JSON

[英]How to upload and convert XLSX file to JSON using ember.js

I am trying to allow the user to upload an XLSX file to be converted to a JSON or CSV file to be parsed through on the back-end. 我试图允许用户上传XLSX文件,以将其转换为JSON或CSV文件,以便在后端进行解析。 I am using node.js, and tried several packages including the read-excel-file ( https://github.com/catamphetamine/read-excel-file/blob/master/README.md ) 我正在使用node.js,并尝试了多个包,包括read-excel-file( https://github.com/catamphetamine/read-excel-file/blob/master/README.md

readXlsxFile(file).then(function(data) {
let jsondata = JSON.parse(data);
-do something with jsondata-
});

The usual place to look for add-ons would be Ember Observer but the options available seem have a status of Work In Progress - they might be a useful place to look though to get some inspiration for how to proceed. 寻找附加组件的通常地方是Ember Observer,但是可用的选项似乎处在进行中的状态-它们可能是一个有用的地方,尽管可以从中获得一些灵感来进行操作。

There are plenty of options on npm . npm上有很多选择。 You can import one of those into your project using the new add-on ember-auto-import or, if you'd rather do the hard work yourself, the Ember guides provide some guidance on manually importing . 您可以使用新的插件ember-auto-import将其中之一导入到您的项目中,或者,如果您愿意自己辛苦工作,则Ember指南提供了一些有关手动导入的指南

You can use js-xlsx . 您可以使用js-xlsx Add it as bower dependecy and add its imports to your ember-cli-build file as: 将其添加为BowerDependecy,并将其导入添加为您的ember-cli-build文件,如下所示:

app.import('bower_components/js-xlsx/dist/jszip.js');
app.import('bower_components/js-xlsx/dist/xlsx.min.js');

Handle it as the documentation's parsing-workbooks section shows. 按照文档的解析工作簿部分所示进行处理。 ( handleFile function is explaining it well.) handleFile函数很好地解释了这一点。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM