i am currently working on a form which will take user input and add it to one row of an excel sheet, as of now i have managed to make excel sheet using 3rd party plugins(node-xls to be specific). issue arises if i wanna add another row to the excel , it deletes the old entry and adds the new instead of appending the data to the next row.
我目前正在处理一个表单,它将接受用户输入并将其添加到excel表的一行,截至目前我已设法使用第三方插件制作excel表(node-xls是特定的)。如果我想在excel中添加另一行,它会删除旧条目并添加新条目而不是将数据附加到下一行。
tried reading the excel and then concatenating the buffers and writing the file again, but turns out it is corrupting the file and is rendering it unusable.
尝试读取excel,然后连接缓冲区并再次写入文件,但事实证明它正在破坏文件并使其无法使用。
How do i append data to the end of the excel sheet? i am new to nodejs and buffers
如何将数据附加到Excel工作表的末尾?我是nodejs和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!");
});
3 个解决方案
#1
2
Have you tried Exceljs. It helps in Read, manipulate and write spreadsheet data and styles to XLSX and JSON.
你试过Exceljs吗?它有助于读取,操作和编写电子表格数据和样式到XLSX和JSON。
check on the below link for details
请查看以下链接了解详情
https://www.npmjs.com/package/exceljs
https://www.npmjs.com/package/exceljs
Your problem of adding rows or append 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
0
Install npm module 'spread_sheet', it will definitely resolve the issues of adding row as well as reading rows from spreadsheet from any sheet.
安装npm模块'spread_sheet',它肯定会解决添加行以及从任何工作表中读取电子表格中的行的问题。
#3
0
It will add one row 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)
})
#1
2
Have you tried Exceljs. It helps in Read, manipulate and write spreadsheet data and styles to XLSX and JSON.
你试过Exceljs吗?它有助于读取,操作和编写电子表格数据和样式到XLSX和JSON。
check on the below link for details
请查看以下链接了解详情
https://www.npmjs.com/package/exceljs
https://www.npmjs.com/package/exceljs
Your problem of adding rows or append 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
0
Install npm module 'spread_sheet', it will definitely resolve the issues of adding row as well as reading rows from spreadsheet from any sheet.
安装npm模块'spread_sheet',它肯定会解决添加行以及从任何工作表中读取电子表格中的行的问题。
#3
0
It will add one row 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)
})