I am learning Nodejs and I am reading and writing the excel file using Nodejs by the module "XLSX" npm. Reading and writing the data done successfully. But there is an external row which is inserting in place of first row and the data of row is [A, B, C, D..... the column name].
How to solve that problem? the code is below.
{
var filepath = './src/assets/uploads/csv template/fileName.csv';
var workbook = XLSX.readFile(filepath);
var sheet_name_list = workbook.SheetNames;
var xlData = XLSX.utils.sheet_to_json(workbook.Sheets[sheet_name_list[0]], { header: 'A' });
let worksheet = workbook.Sheets[sheet_name_list[0]];
if(xlData){
xlData[0]["L"] = "hash";
for(let i = 1; i< xlData.length; i++){
xlData[i]["L"] = generatehasnumber(xlData[i]["A"], xlData[i]["D"]);
}
}
if(xlData[1]["A"] == "A" )
{
xlData.shift();
}
const ws = XLSX.utils.json_to_sheet(xlData)
const wb = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(wb, ws, "hash")
XLSX.writeFile(wb, './src/assets/uploads/csv template/fileName.csv')
}
try adding the flag for not including header row in output:
const ws = XLSX.utils.json_to_sheet(xlData, { skipHeader: true })