I am a nodejs programmer . Now I have a table of data that I want to save in Excel File format . How do I go about doing this ?
I found a few Node libraries . But most of them are Excel Parsers rather than Excel Writers .I am using a Linux Server . Hence need something that can run on Linux . Please let me know if there are any helpful libraries that you know of .
Or is there a way I can convert a CSV file to an xls file ( programmatically ) ?
I just figured a simple way out . This works -
Just create a file with Tabs as delimiters ( similar to CSV but replace comma with Tab ). Save it with extension .XLS . The file can be opened in Excel .
Some code to help --
var fs = require('fs'); var writeStream = fs.createWriteStream("file.xls"); var header="Sl No"+"\t"+" Age"+"\t"+"Name"+"\n"; var row1 = "0"+"\t"+" 21"+"\t"+"Rob"+"\n"; var row2 = "1"+"\t"+" 22"+"\t"+"bob"+"\n"; writeStream.write(header); writeStream.write(row1); writeStream.write(row2); writeStream.close();
This creates the file in XLS file format . It doesnt work if you try XLSX instead of XLS .