Skip to content

Adopt upstream PR #2978: Fix undefined column autofilter assignment #22

@protobi-pieter

Description

@protobi-pieter

Summary

Adopt upstream PR exceljs#2978 (partial) to fix crashes when autofilter column index refers to an undefined column.

In some Excel files, the autofilter configuration references column indices that don't exist in the table model, causing crashes when trying to assign the filterButton property to undefined columns.

Upstream PR

Changes

File modified:

  • lib/xlsx/xform/table/table-xform.js - Add guard for undefined columns (3 lines)

Total: 3 additions, 0 deletions

Note: The upstream PR includes additional changes to data-validations-xform.js and package.json. We are only adopting the table-xform.js fix as it's the core bug fix. The other changes are either unrelated or inappropriate for our fork.

Bug Description

When parsing Excel files with autofilter configurations that reference non-existent columns, ExcelJS crashes trying to set properties on undefined objects.

Current behavior:

this.map.autoFilter.model.columns.forEach((column, index) => {
  this.model.columns[index].filterButton = column.filterButton;
  // Crashes if this.model.columns[index] is undefined
});

Fixed behavior:

this.map.autoFilter.model.columns.forEach((column, index) => {
  if (!this.model.columns[index]) {
    return;  // Skip undefined columns
  }
  this.model.columns[index].filterButton = column.filterButton;
});

Value Proposition

  • Low Risk - Simple guard clause addition
  • Bug Fix - Prevents crashes on malformed Excel files
  • Robustness - Improves error handling for edge cases

Testing Plan

  • Apply changes from upstream PR (table-xform.js only)
  • Run existing test suite
  • Verify files with mismatched autofilter indices don't crash

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