Skip to content

[BUG] Formulae in "Formatting Rules" throws exception #2311

@jonathankeebler

Description

@jonathankeebler

🐛 Bug Report

If a formatting rule is setup for a sheet, that references another sheet, an exception is thrown when you call XLSX.writeBuffer
Screenshot 2023-07-19 at 2 51 12 PM

Cell model looks like this:

{
  type: 'expression',
  x14Id: '{BB2F621F-E459-4F3E-9A72-51C5F7F3EB5F}',
  priority: 42,
  ref: 'C16'
}

Exception:

TypeError: Cannot read properties of undefined (reading 'forEach')
    at CfRuleXform.renderCellIs (/Users/jonathan/baseline/service-2.0/node_modules/exceljs/lib/xlsx/xform/sheet/cf/cf-rule-xform.js:175:20)
    at CfRuleXform.render (/Users/jonathan/baseline/service-2.0/node_modules/exceljs/lib/xlsx/xform/sheet/cf/cf-rule-xform.js:125:14)
    at /Users/jonathan/baseline/service-2.0/node_modules/exceljs/lib/xlsx/xform/sheet/cf/conditional-formatting-xform.js:29:25
    at Array.forEach (<anonymous>)
    at ConditionalFormattingXform.render (/Users/jonathan/baseline/service-2.0/node_modules/exceljs/lib/xlsx/xform/sheet/cf/conditional-formatting-xform.js:26:17)
    at /Users/jonathan/baseline/service-2.0/node_modules/exceljs/lib/xlsx/xform/sheet/cf/conditional-formattings-xform.js:41:20
    at Array.forEach (<anonymous>)
    at ConditionalFormattingsXform.render (/Users/jonathan/baseline/service-2.0/node_modules/exceljs/lib/xlsx/xform/sheet/cf/conditional-formattings-xform.js:40:11)
    at WorkSheetXform.render (/Users/jonathan/baseline/service-2.0/node_modules/exceljs/lib/xlsx/xform/sheet/worksheet-xform.js:329:36)
    at /Users/jonathan/baseline/service-2.0/node_modules/exceljs/lib/xlsx/xlsx.js:562:22
    at Array.forEach (<anonymous>)
    at XLSX.addWorksheets (/Users/jonathan/baseline/service-2.0/node_modules/exceljs/lib/xlsx/xlsx.js:560:22)
    at XLSX.write (/Users/jonathan/baseline/service-2.0/node_modules/exceljs/lib/xlsx/xlsx.js:654:16)
    at async XLSX.writeBuffer (/Users/jonathan/baseline/service-2.0/node_modules/exceljs/lib/xlsx/xlsx.js:684:5)

Lib version: 4.3.0

Steps To Reproduce

sample.xlsx

const workbook = new Excel.Workbook();
await workbook.xlsx.load(file);
await workbook.xlsx.writeBuffer();

The expected behaviour:

The conditional formatting is applied.

Possible solution (optional, but very helpful):

In /lib/xlsx/xform/sheet/cf/cf-rule-xform.js, this code could be patched to not assume formulae is set:

renderExpression(xmlStream, model) {
    xmlStream.openNode(this.tag, {
      type: 'expression',
      dxfId: model.dxfId,
      priority: model.priority,
    });

    this.formulaXform.render(xmlStream, model.formulae[0]);

    xmlStream.closeNode();
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy