Reputation: 67
Below is my code Ws-Contains redundant data while wsRemDup-contains data after removing the redundant/duplicate data. wsRemDup is an array of JSON.
I want to overwrite my ws sheets data with wsRemDup. I googled to find a way but most of the stuff showed how to append instead of overwriting it. How can I proceed?
ws = XLSX.utils.sheet_add_json(ws, ticketNameArr,{origin:-1, skipHeader:true});
//Contains unique ticket name and their other fields
wsRemDup=removeDuplicate(ws)
console.log(wsRemDup)
XLSX.writeFile(wb, 'DailyTicketSatus.xlsx')
respond.render('index', { "ticketNameArr": ticketNameArr });
Upvotes: 0
Views: 4592
Reputation: 30675
You should be able to overwrite the sheet on your original workbook like so:
const excelFile = "tickets.xlsx";
const sheetName = "Sheet1" // <-- Change to the actual sheet name.
const workbook = XLSX.readFile(excelFile);
const ws = workbook.Sheets[sheetName];
let sheetJson = removeDuplicate(ws);
// Overwrite worksheet
workbook.Sheets[sheetName] = XLSX.utils.json_to_sheet(sheetJson);
XLSX.writeFile(workbook, excelFile);
Upvotes: 4