-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
Description
when I am using fill style to fill a cell, its also filling other cells.
input is,
let xlManipulate = async (email = 'Email ID',filePath) => {
let workbook = new Excel.Workbook();
filePath = path.resolve(__dirname, 'Bulk Download_Upload (1).xlsx');
await workbook.xlsx.readFile(filePath) // reading workbook
let isDirtyFile=0;
let fill = { //cell filling proprerty
type: 'pattern',
pattern: 'darkVertical',
fgColor: { argb: 'FFFFFF00' },
bgColor: { argb: 'FFFFFF0F' }
};
let border = {
diagonal: { up: true, down: true, style: 'thick', color: { argb: 'FFFF0000' } }
};
// let worksheet=workbook.getWorksheet('Consultant Details');
workbook.eachSheet(async (worksheet, sheetId)=> { // reading one sheet at a time
let emailData = new Set();
let lengthOf = 0;
let cellNo = 1;
let rowLength=0;
worksheet.eachRow((row, rowNumber) => { //reading row at a time
//console.log(row.values,rowNumber);
if (rowNumber === 1) { // getting email header index
cellNo = row.values.indexOf(email);
rowLength = row.values.length;
}
//console.log(cellNo);
let cell = row.getCell(cellNo);
emailData.add(cell.value);
if (emailData.size === lengthOf) {
console.log(cell.fill,'++++',cell.value);
cell.fill = fill; //cell filling proprerty
// cell.border=border;
// row.getCell(rowLength).fill=fill;
row.getCell(rowLength).value='duplicate'; // adding comment
//console.log(cell.value);
row.commit();
isDirtyFile=1;
}
else {
console.log(cell.fill,'====',cell.value);
lengthOf = emailData.size;
}
});
});
//Save the workbook
if(isDirtyFile===1)
// await workbook.xlsx.writeFile(filePath);
await workbook.xlsx.writeFile(path.resolve(__dirname, 'Bulk Download_Upload.xlsx'));
return Promise.resolve(isDirtyFile);
}