Thanks to visit codestin.com
Credit goes to github.com

Skip to content

cell.fill issue #791

@ns20011997

Description

@ns20011997

when I am using fill style to fill a cell, its also filling other cells.
input is,
Screenshot 2019-04-24 at 11 07 17 AM

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);
}

and the output is,
Screenshot 2019-04-24 at 11 05 44 AM

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions