How to upload and convert XLSX file to JSON using ember.js - javascript

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. 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)
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.
There are plenty of options on 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.

You can use js-xlsx. Add it as bower dependecy and add its imports to your ember-cli-build file as:
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.)

Related

How to read worldedit .schem file with nodejs

I'm trying to make a node application that uploads .schem files but I don't know how to use the fs import to read the file without modifying it. When I try to read and write the file again the data gets modified and world edit in minecraft can't read it.
Can someone please help me with this?
As you can see here the .schem files are saved using NBT, and its structure.
the nbt format is using binary format (comparing to json that you can read and modify easily). so you probably want to use an existing library, i have never programed in node.js but i found this, if it helps

Webpack: Custom loader - reuse file extension

I'm working on writing a loader for filename.xyz.json files.
Now since Webpack version 2, Webpack support loading JSON files out of the box.
So I've managed to get my loader to work when working when using a completely custom file extension like .xyz.jayson.
But because I'm using .json the other, already existing loader gets triggered after my loader did his magic, which will cause an error because at this point it's not JSON anymore. How can I prevent that?
If I understand the Webpack docs correctly, the !! prefix with inline usage would do just that. But I would like to disable post/pre loaders in the config. Is this possible?
Also, I was thinking of actually using that given JSON loader instead of dodging it, because why parse the JSON myself, when there is already a loader for it? But I don't quite sure if that is possible since the returned source from the JSON is already returned as module.export. Would I need to strip the module.export and then run JSON.parse to work with it as an actual js object instead of a string?
So as a quick summary:
I'd like to either to not trigger the JSON loader at all, and parse the JSON myself to manipulate it or use the built-in JSON loader first and then manipulate the JSON data file myself.
I found the solution:
Setting the type of my rule to javascript/auto gave me the expected result.
More information here

Alasql and Angular; jszip is not a constructor error

So reading another article and solution here I found the library Alasql which seems to do what I need.
I've installed it and was writing a proof-of-concept application to use it and when I attempt to use the illustration given in that article I get:
Error: jszip is not a constructor
write_zip#https://server:8443/vendor/js-xlsx/dist/xlsx.js:11295:12
write_zip_type#https://server:8443/vendor/js-xlsx/dist/xlsx.js:11407:10
writeSync#https://server/vendor/js-xlsx/dist/xlsx.js:11421:1
saveWorkbook#https://server:8443/vendor/alasql/dist/alasql.js:15656:17
doExport#https://server/vendor/alasql/dist/alasql.js:15556:3
alasql.into.XLSX#https://server/vendor/alasql/dist/alasql.js:15529:3
anonymous#https://server/vendor/alasql/dist/alasql.js line 7343 > Function:1:14
queryfn3#https://server/vendor/alasql/dist/alasql.js:6528:13
queryfn2#https://server/vendor/alasql/dist/alasql.js:6274:9
anonymous#https://server/vendor/alasql/dist/alasql.js line 7757 > Function:1:57
queryfn/<#https://server/vendor/alasql/dist/alasql.js:6223:12
queryfn#https://server/vendor/alasql/dist/alasql.js:6219:2
yy.Select.prototype.compile/statement#https://server/vendor/alasql/dist/alasql.js:7352:14
alasql.dexec#https://server/vendor/alasql/dist/alasql.js:4240:27
alasql.exec#https://server/vendor/alasql/dist/alasql.js:4190:10
alasql#https://server/vendor/alasql/dist/alasql.js:121:11
Index#https://server/app/states/index/index.controller.js:20:23
And those errors keep going as is the custom of Angular.
Looking for a solution I found https://github.com/SheetJS/js-xlsx/issues/184 but that didn't seem to help me out at all.
So I'm wondering if other people have encountered this and what their solution to the problem was as I'd really like to use this library but can't even get their example code to work.
EDIT:
So for those who might be coming up with the same problem...the solution I found was to add the JSZip library to my application (even though it looks like it was included with the SheetJs library) and made sure it was loaded before the Alasql piece. That seems to have done the trick...
It seems you are using it with requirejs or some dependency library
You will either need to include all .js files with the distribution or add them as a dependency in shim

Learning Leaflet. Noticed examples add a var name to the GeoJson file. Necessary?

I'm learning Leaflet, JS, etc. Am testing using code examples from the Leaflet site, modified for my use. In all the example I've looked at, the JSON file has a var added in front of the initial bracket ([). Is this necessary to work with a JSON file? It sure would be nice to have the JSON files work as they are generated. ArcMap Desktop, for example, has a tool called Feature-to-JSON and the output does not have a "var = name" as the first data. Can I avoid the step of adding the var? If so, I'd appreciate code examples.
You definitely don't have to save your JSON files as JavaScript files. It is used in the examples just for simplicity. Normally, you have your JSON file on your server or accessible with some REST API. This file can be asynchronously downloaded and used in your map like this:
myHttpService.get(myFileUrl).then(function(jsonData) {
L.geoJson(jsonData).addTo(map);
});

I want to unzip a file with javascript from a file or blob object

I would like to read a pptx file in javascript, so I would like to unzip it and read the content in memory. I don't want to store the file first on a server. I want to choose a file with a input type file and just use the file of the input-element and read it binary or something like that.
I found a lot of libraries to unzip zip-files from url, I tried to look at the code but I couldn't figure it out to use it for a blob or byte array.
I can read some stuff like the things described here: http://en.wikipedia.org/wiki/ZIP_%28file_format%29#File_headers
But I don't know how deflating works on byte- or bit-level.
(You've said you want to use an input element, so I'm guessing this is browser-based JavaScript.)
Your first step will be to use the File API to read the file as a binary string. See my answer to this other question for an example of that. Then you'll need to find a library. A quick search discovered this one that implements both inflate and deflate. (I don't have personal experience using it, just found it in an answer to this other question.)
Naturally this will only work on quite modern browsers that support the File API. Otherwise, you have no option but to push the file to a server and do the work there, since you can't access the content of the file in the browser without the File API.

Categories

Resources