exceljs 条件格式的单元格

时间:2021-03-18 14:13:03

标签: javascript exceljs

我正在使用 exceljs 创建一个 excel 工作簿。工作表的范围为 A1:AR106。我的数据对象将包含 3 个属性(numtype、nummax、nummin)。只有属性 nummax 和 nummin 会出现在工作表上。我可以成功创建带有格式的工作簿,但我无法使单个单元格的条件格式工作。

我想根据 numtype 的值为单元格着色。例如,如果 numtype = 'abc',则 nummin 单元格将是浅蓝色,而 nummax 将是浅红色。所以我会针对 numtype 的其他可能值扩展它,并相应地为 nummin/nummax 设置颜色。

我在 https://github.com/exceljs/exceljs#conditional-formatting 找到了 exceljs 的文档 但我一直无法使单元格的条件格式适合我。

        worksheet.addConditionalFormatting({
          ref: 'A3:AR106',
          rules: [
            {
              type: 'containsText',
              operator: 'containsText',
              text: 'abc',
              style: {fill: {type: 'pattern', pattern: 'solid', bgColor: {argb: '#98b8eb'}}},
            }
          ]
        })

有没有人有我可以效仿的例子来证明我所描述的内容?

谢谢 丹

1 个答案:

答案 0 :(得分:0)

我在 https://www.freakyjolly.com/create-excel-from-json-in-angular-98-using-exceljs-tutorial-with-example/#.YFPFM2RKiqA 的子标题“有条件地格式化单元格”下找到了满足我需求的合理解决方案

我认为它也可以针对其他条件格式需求进行定制。对我很有用。

相关问题