简体   繁体   English

exceljs条件格式的单元格

[英]exceljs conditional formatting of cells

I am using exceljs to create an excel workbook.我正在使用 exceljs 创建 excel 工作簿。 A sheet will have a range of A1:AR106.工作表的范围为 A1:AR106。 My data objects will contain 3 properties (numtype, nummax, nummin).我的数据对象将包含 3 个属性(numtype、nummax、nummin)。 Only properties nummax and nummin will appear on the sheet.只有属性 nummax 和 nummin 会出现在工作表上。 I can successfully create the workbook with formatting but I am not able to make conditional formatting of individual cells work.我可以成功地创建带有格式的工作簿,但我无法使单个单元格的条件格式起作用。

I would like to color cells depending on the value of numtype.我想根据 numtype 的值为单元格着色。 For example, if numtype = 'abc', the nummin cell will be lightblue and nummax will be lightred.例如,如果 numtype = 'abc',则 nummin 单元格将为浅蓝色,而 nummax 将为浅红色。 So i would expand this for other possible values of numtype and set colors for nummin/nummax accordingly.因此,我会将其扩展为其他可能的 numtype 值,并相应地将 colors 设置为 nummin/nummax。

I found documentation for exceljs at https://github.com/exceljs/exceljs#conditional-formatting but I have not been able to make conditional formatting of cells work for me.我在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'}}},
            }
          ]
        })

Does anyone have an example I could follow that would lend itself to what I have described?有没有人有一个我可以效仿的例子,适合我所描述的?

Thanks Dan谢谢丹

I found a reasonable solution to meet my needs at https://www.freakyjolly.com/create-excel-from-json-in-angular-98-using-exceljs-tutorial-with-example/#.YFPFM2RKiqA under sub-heading "Formatting Cells Conditionally"我在https://www.freakyjolly.com/create-excel-from-json-in-angular-98-using-exceljs-tutorial-with-example/#.YFPFM2RKiqA下找到了一个合理的解决方案来满足我的需求标题“有条件地格式化单元格”

I think it could be tailored to work for other conditional formatting needs as well.我认为它也可以针对其他条件格式需求进行定制。 Worked great for me.对我来说效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM