Skip to content

[BUG] Error parsing dynamicFilter in Excel table: "Unexpected xml node in parseOpen" #2972

@johnnyoshika

Description

@johnnyoshika

🐛 Bug Report

Full repo to easily reproduce this bug is available here: https://github.com/examind-ai/exceljs-dynamicfilter-bug

Lib version: 4.4.0

ExcelJS fails to parse Excel files containing dynamicFilter elements in table XML with the error: Unexpected xml node in parseOpen. This occurs when Excel tables use dynamic filters (like "Above Average"), but only affects table-level filters - worksheet-level dynamic filters parse successfully.

Steps To Reproduce

  1. Open Excel
  2. Create a new workbook
  3. Add sample data
ID Age
1 10
2 11
3 12
4 13
5 14
6 15
7 16
8 17
9 18
10 19
  1. Convert to a table: Insert -> Table
  2. Select the Age filter and choose: Number filters -> Above Average

Then try to load that file into exceljs with:

  const workbook = new ExcelJS.Workbook();
  await workbook.xlsx.readFile('excel-file.xlsx');

The expected behaviour:

Expect ExcelJS to not throw an exception. Instead, it results in this exception:

exceljs-dynamicfilter-bug\node_modules\exceljs\lib\xlsx\xform\table\filter-column-xform.js:72
        throw new Error(`Unexpected xml node in parseOpen: ${JSON.stringify(node)}`);
              ^

Error: Unexpected xml node in parseOpen: {"name":"dynamicFilter","attributes":{"type":"aboveAverage","val":"14.5"},"isSelfClosing":true}
    at FilterColumnXform.parseOpen (exceljs-dynamicfilter-bug\node_modules\exceljs\lib\xlsx\xform\table\filter-column-xform.js:72:15)
    at AutoFilterXform.parseOpen (exceljs-dynamicfilter-bug\node_modules\exceljs\lib\xlsx\xform\table\auto-filter-xform.js:37:19)
    at TableXform.parseOpen (exceljs-dynamicfilter-bug\node_modules\exceljs\lib\xlsx\xform\table\table-xform.js:57:19)
    at TableXform.parse (exceljs-dynamicfilter-bug\node_modules\exceljs\lib\xlsx\xform\base-xform.js:63:16)
    at async XLSX._processTableEntry (exceljs-dynamicfilter-bug\node_modules\exceljs\lib\xlsx\xlsx.js:165:19)
    at async XLSX.load (exceljs-dynamicfilter-bug\node_modules\exceljs\lib\xlsx\xlsx.js:393:15)
    at async XLSX.readFile (exceljs-dynamicfilter-bug\node_modules\exceljs\lib\xlsx\xlsx.js:55:24)

Full repo to easily reproduce this bug is available here: https://github.com/examind-ai/exceljs-dynamicfilter-bug

Possible solution (optional, but very helpful):

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