Skip to content

[BUG] Adding Data Validation and Conditional Formatting to the same sheet causes corrupt workbook #1118

@ghost

Description

🐛 Bug Report

Adding Data Validation to a sheet and then writing the workbook works as expected and so does adding Conditional Validation.

However, when adding both to the same sheet, then writing the workbook, the code runs successfully, but when opening the excel file, the "We found a problem with some content in...." prompt appears.

Lib version: 3.8.0

Steps To Reproduce

Run the following.
Data Validation and Conditional Formatting examples taken from README.

let Excel = require('exceljs')

let workbook = new Excel.Workbook()

let worksheet = workbook.addWorksheet('Sheet 1')

worksheet.addConditionalFormatting({
  ref: 'A1:E7',
  rules: [
    {
      type: 'expression',
      formulae: ['MOD(ROW()+COLUMN(),2)=0'],
      style: { fill: { type: 'pattern', pattern: 'solid', bgColor: { argb: 'FF00FF00' } } },
    }
  ]
})

worksheet.getCell('G1').dataValidation = {
  type: 'list',
  allowBlank: true,
  formulae: ['"One,Two,Three,Four"']
};

workbook.xlsx.writeFile('./test-book.xlsx')

The expected behaviour:

The Excel workbook can be opened as normal and has Data Validation and Conditional Formatting rules in the same sheet

Extra details

In the simple example above, it seems that excel can recover, but the recovered file is not useful.

The recovery message: Replaced Part: /xl/worksheets/sheet1.xml part with XML error. Load error. Line 2, column 718.

The order of inserting validation/cond. formatting rules doesn't seem to matter.

Whether the the validation and cond. formatting are applied to the same or different cells doesn't seem to matter.

Applying cond. formatting to one sheet, then applying data validation to a different sheet in the same workbook works as expected

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions