I succeeded in reading the existing Excel file and putting the data in the cell location I wanted. But after we put the data in, all the ExcelCharts in the existing Excel file disappeared. I'm still looking for a solution, but I can't solve it.
workbook.xlsx.readFile(__dirname + "/../assets/ExcelFile/testFile.xlsx")
.then(function() {
var worksheet = workbook.getWorksheet(8);
for(var i=1; i<data.length+1; i++)
{
for(var j=1; j<data[i-1].length+1; j++)
{
if(data[i-1][0] == "Slaes rate of electricity")
{
Price = data[i-1][2].replace(/,/gi,"");
worksheet.getRow(12).getCell(7).value = Number(Price);
}
else if (data[i-1][0] == "Average coal HHV")
{
Price = data[i-1][2].replace(/,/gi,"");
worksheet.getRow(15).getCell(7).value = Number(Price);
}
else if (data[i-1][0] == "Average price of coal")
{
Price = data[i-1][2].replace(/,/gi,"");
worksheet.getRow(16).getCell(7).value = Number(Price);
}
}
}
return workbook.xlsx.writeFile(__dirname + "/../assets/ExcelFile/Test_"+getTimeStamp()+".xlsx");
})
.then(function() {
res.send("true");
})
.catch(function(error) {
console.dir(error);
res.send(error);
})