Convert txt to xls - nodejs
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

We need a POC concept node script that will take our txt file (upload in simple form) and output a well structured xls file (download when done would be great). Thinking maybe this lib works well here https://github.com/SheetJS/sheetjs#supported-output-formats since it supports xls specifically. Ideally your solution can run in repl.it. we can have the txt file uploaded and then the script will run and output a xls file either in the browser or in the folder structure of your solution.

here is a sample file. at the moment we are using | as the delimiter but let us know if there is something more ideal here. https://gist.github.com/quotient/6e4c6a3a62d0ba5b1c60d183cdd0f572

Hoping you can use a common well supported lib maybe like https://github.com/SheetJS/sheetjs#supported-output-formats since it seems to handle new and old excel formats.

awarded to svipal

Crowdsource coding tasks.

1 Solution

Winning solution

I have something that works with a super basic page + download when done.

The only caveat is that the file has to use the excel guidelines for nonstandard separators, so you would have to add sep=| at the first line of the file if you wanted to use that separator and have correct output.

(I included the file example in the repl it as well)
Let me know if this is what you were looking for.

For some reason the download wont work in repl it but it will locally and you can dowload it from repl.it.
It's in files/output.xls.

https://replit.com/@svipal/sheetjs#index.js

here is the direct link to the modified file that would output correct xls. https://replit.com/@svipal/sheetjs#input_example.txt Just noticed these links dont work if you are not in creator mode lol, wel
svipal 4 months ago
A bit bummed about the download link not working in repl.it... sure it works locally, maybe there's a protection I'm not aware of.
svipal 4 months ago
to be absolutely honest the real solution is in three lines, once your file has the correct format, the library does all the work, the rest is just fluff : const XLSX = require('xlsx'); const txt = XLSX.readFile('path/to/your/input.txt'); XLSX.writeFile(txt, 'path/to/your/output.xls');
svipal 4 months ago
seems perfect. we are checking it now.
Qdev 4 months ago