question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
Siemienikcommented, Apr 25, 2019

@ns20011997 it is probably a similar issue like here: https://github.com/exceljs/exceljs/issues/669 (PR: https://github.com/exceljs/exceljs/pull/722)

if I am right, this workaround should works:

cell.style = JSON.parse(JSON.stringify(cell.style)); //very bad way to clone anythink, but works.
cell.fill = fill
3reactions
DantSucommented, Jul 7, 2020

Steps :

  • create a file
  • open it with MS excel
  • select cells A1 to C5 (It’s an example)
  • assign a style
  • close the file
  • open it with exceljs
  • run ws.getCell('B2').font = {...cell.font, color: {argb: 'FF3366FF'}}
  • style of A1 to C5 will be changed

Workaround

const cell = ws.getCell('B2')
cell.style = {
   ...cell.style,
   font: {...cell.font, color: {argb: 'FF3366FF'}}
}

Idea

May be, create a method setStyle() on Cell class.

setStyle(style) {
  this.style = {...this.style, ...style}
}

Use example :

const cell = ws.getCell('B2')
cell.style = {
   ...cell.style,
   font: {...cell.font, color: {argb: 'FF3366FF'}}
}

become :

const cell = ws.getCell('B2')
cell.setStyle({font: {...cell.font, color: {argb: 'FF3366FF'}}})

Use example :

const cell = ws.getCell('B2')
cell.style = {
  ...cell.style,
  fill: {
    type: 'pattern',
    pattern: 'solid',
    fgColor: {argb: 'FFD8D8D8'}
  }
}

become :

ws.getCell('B2').setStyle({
  fill: {
    type: 'pattern',
    pattern: 'solid',
    fgColor: {argb: 'FFD8D8D8'}
  }
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Color Fill not working - Microsoft Community Hub
I am trying to do a simple color fill of a cell and it just won't work. What can I do? I have...
Read more >
How to Fix When Fill Color Doesn't Display Properly in Excel
First, make sure that the cells you're trying to fill are actually selected. If they're not, the fill color won't show up. Next,...
Read more >
Excel drag to “fill” not working – value is copied, formula ignored
You might also run into drag-to-fill issues if you're filtering. Try removing all filters and dragging again.
Read more >
Table Cell Shading – White Space – Troubleshooting
When attempting to apply shading to tables, you may meet with the problem that one or more cells are not totally filled with...
Read more >
Why Fill Handle Excel not working? | MyExcelOnline
It can even be that you have not selected the entire range that has your sequential values. Just selecting the last cell will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found