如何使用 ember.js 上传 XLSX 文件并将其转换为 JSON
How to upload and convert XLSX file to JSON using ember.js
我正在尝试让用户上传 XLSX 文件以将其转换为 JSON 或 CSV 文件以在后端进行解析。我正在使用 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-
});
您可以使用 js-xlsx。将其添加为 bower 依赖项并将其导入添加到您的 ember-cli-build
文件中:
app.import('bower_components/js-xlsx/dist/jszip.js');
app.import('bower_components/js-xlsx/dist/xlsx.min.js');
按照文档的 parsing-workbooks 部分所示进行处理。 (handleFile
函数解释得很好。)
寻找附加组件的通常位置是 Ember Observer,但可用选项的状态似乎是“进行中”——它们可能是一个有用的地方,可以从中获得一些灵感,了解如何继续。
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 上有很多选择。
我正在尝试让用户上传 XLSX 文件以将其转换为 JSON 或 CSV 文件以在后端进行解析。我正在使用 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-
});
您可以使用 js-xlsx。将其添加为 bower 依赖项并将其导入添加到您的 ember-cli-build
文件中:
app.import('bower_components/js-xlsx/dist/jszip.js');
app.import('bower_components/js-xlsx/dist/xlsx.min.js');
按照文档的 parsing-workbooks 部分所示进行处理。 (handleFile
函数解释得很好。)
寻找附加组件的通常位置是 Ember Observer,但可用选项的状态似乎是“进行中”——它们可能是一个有用的地方,可以从中获得一些灵感,了解如何继续。
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 上有很多选择。