Skip to content

Conversation

@huyunan
Copy link

@huyunan huyunan commented Dec 19, 2020

Summary

After all the borders of (A1: B1) are set, read the excel file, and then change the background color of cell A1. The background color of cell B1 will also change.
create test_a.xlsx

  const wb = new ExcelJS.Workbook();
  const worksheet = wb.addWorksheet('Sheet1');
  const border = {"left":{"style":"thin"},"right":{"style":"thin"},"top":{"style":"thin"},"bottom":{"style":"thin"}};
  worksheet.getCell('A1').style.border = border;
  worksheet.getCell('A1').value = 'A1';
  worksheet.getCell('B1').style.border = border;
  worksheet.getCell('B1').value = 'B1';
  wb.xlsx.writeFile(path.resolve('./spec/unit/doc/test_a.xlsx'));

image
Then read excel

  const wb = new ExcelJS.Workbook();
  const workbook = await wb.xlsx.readFile('./spec/unit/doc/test_a.xlsx');
  workbook.getWorksheet(1).getCell('A1').style.fill = {
    type: 'pattern',
    pattern: 'solid',
    fgColor: { argb: 'FFFF0000' },
    bgColor: { indexed: 64 }
  };
  console.log(workbook.getWorksheet(1).getCell('A1').style.fill === workbook.getWorksheet(1).getCell('B1').style.fill);
  // **true**

  console.log(workbook.getWorksheet(1).getCell('B1').style.fill);
  console.log(workbook.getWorksheet(1).getCell('A1').style.fill);
  workbook.xlsx.writeFile(path.resolve('./spec/unit/doc/test_a0000.xlsx'));

fill A1 with red solid but A2 also red solid
image

Test plan spec\unit\utils

A simple test is included in spec/unit/utils/utils.spec.js

…hen change the background color of cell A1. The background color of cell B1 will also change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant