Scramjet with xlsx - node.js

Is it possible to use scramjet with xlsx files?
I have seen scramjet implementation with csv's such as fast-csv.
Data-streams of scramjet with fast-csv can read row by row which are then used as per need while with xlsx we have to read the whole file or complete the stream i.e. on stream end read the whole file using xlsx and perform action.
Library in consideration 'scramjet' npm.
For xlsx files 'xlsx' npm.
For csv files 'fast-csv' npm.

Related

How can I convert a .numbers file to .xlsx file using the xlsx library in Node.js?

How can I convert a .numbers file to an .xlsx file using the xlsx library in nodejs? The documentation states that Numbers is not included in the library by default, and you must use the xlsx.zuhl.js, xlsx.zuhl.mjs scripts. In the documentation for xlsx library there is example how to use script for exporting Numbers files, could you write an example of how you can use this script to read Numbers file format and convert it to .xlsx?
Is there any other way to convert .numbers file to .xlsx?

Reading an Excel file with fs.createReadStream

I am new to node js
I want to print excel data without using any library as using libraries takes time and we have to deal with large memory files.
I tried reading a .xlsx file using fs.createReadStream() and logged the data to console, it prints some different characters but the actual data.
nodejs code
const stream=fs.createReadStream('example.xlsx');
stream.on('data',function(data){
console.log(Buffer.from(data, 'base64').toString('utf8'))
})
Can I know how to get the actual data or any library that can read large excel files?

Nodejs best way to read xlsx as utf8 text

I need to read xlsx in nodejs. Xlsx contains text with accents and apostrophes and so on. Then i have to save the text in json file.
What are the best practices to perform that task?
Stage 1 - take a look at this module node-xlsx or more robust and possibly better for your needs xlsx.
Stage 2 - Writing the file to JSON - if the module can return a JSON format then great. If you use xlsx it has an option to JSON --> take a look here.
Since you may need to actually strip and/or protect special accents etc. you may need to validate the data which is returned before producing a JSON file.
As to actually writing a JSON file, there are a huge amount of NPM modules for the task.

Trying to convert xlsx to csv using a node stream

I have a lambda script that retrieves an email from s3, parses it with MailParser (streaming), transforms attachments to csv if necessary, and stores them in a different bucket. The script handles csv files (no conversion) and zip files, but I can't figure out how to convert xls to csv using streams.
Exceljs looks really good for this, but I can't get it to work for some reason (and I'm really new to streams so that's probably it).
var workbook = new Excel.Workbook();
var xstream = workbook.xlsx.createInputStream();
xstream.on('done', function(data) {
// convert to csv and s3.upload
});
attachment.stream
.pipe(xstream);
I'm getting an error
Error: Unexpected xml node in parseOpen
before the 'done' event so I'm not sure if I'm using createInputStream correctly.

Receive CSV format in Strongloop

I'm trying to receive some data in csv format, what I read is that StrongLoop only works with json data. So can I receive csv and transform to json to process the data?
Thanks.
This isn't a StrongLoop specific question. It is a general Node.js and data question. As such, I will answer in a generic fashion, but it is applicable to StrongLoop.
You will need to use a library to convert the delimited file into a JavaScript object. There are many packages on npm for reading/parsing/transforming/etc. CSV files: search npm.
The package that I have used extensively is David's CSV parser.
These libraries will allow you to parse and transform CSV into JavaScript objects (JSON).
Beware, however, that most CSV that I have dealt with does not conform to well formatted CSV. They don't properly escape quotes, quote strings with delimiters, etc.

Resources