How to add excel file in nodejs

I am currently working on a form that will accept user input and add it to one line of an excel sheet, at the moment I have managed to make an excel sheet using third-party plugins (node-xls to be specific), the problem occurs if I want add another line to excel, it deletes the old record and adds a new one, but does not add data to the next line.

I tried to read excel and then concatenate the buffers and write the file again, but it turns out that it distorts the file and makes it unusable.

How to add data to the end of excel sheet? I'm new to nodejs and buffers

var fs = require('fs'); var NodeXls = require('node-xls'); var tool = new NodeXls(); var xls = tool.json2xls({firstName: "arjun", lastName: "u", dob:"12/3/2008"}, {order:["firstName", "lastName", "dob"]}); fs.appendFile('output.xlsx', xls, 'binary', function(err){ if(err) alert("File is readOnly or is being used by another application, please close it and continue!"); }); 
+6
source share
3 answers

Have you tried Exceljs. It helps to read, process and write data and table styles in XLSX and JSON.

Check out the link below.

https://www.npmjs.com/package/exceljs

Your problem of adding rows or adding rows is solved here:

 worksheet.addRow({id: 1, name: 'John Doe', dob: new Date(1970,1,1)}); var rowValues = []; rowValues[1] = 4; rowValues[5] = 'Kyle'; rowValues[9] = new Date(); worksheet.addRow(rowValues); // Add an array of rows var rows = [ [5,'Bob',new Date()], // row by array {id:6, name: 'Barbara', dob: new Date()} ]; worksheet.addRows(rows); 
+2
source

Install the npm module 'spread_sheet', it will definitely solve the problems of adding a row, as well as reading rows from a spreadsheet from any sheet.

0
source

It will add one line at a time

 var spread_sheet = require('spread_sheet'); var row = "1,2,Jack,Pirate"; var filePath = '/home/Pranjal/Desktop/test.xlsx'; var sheetName = "Sheet1"; spread_sheet.addRow(row,filePath,sheetName,function(err,result){ console.log(err,result) }) 
0
source

All Articles