Skip to content

[BUG] a cells dataValidation is not shifted when splicing rows #1730

@paul-bbn

Description

@paul-bbn

🐛 Bug Report

Data validations are not shifted when adding/deleting rows.

Lib version: 4.2.1

Steps To Reproduce

I got a cell on A1 with a data validation. When I use spliceRows() rows to insert a row above that cell, the validation is still on A1, but I expect it to be on A2. Similar to #737, but for validations.

const workbook = new ExcelJS.Workbook();
const sheet = workbook.addWorksheet("Sheet");
sheet.addRows([[1]]);

const cell = sheet.getCell('A1');
cell.dataValidation = {
  type: "list",
  allowBlank: true,
  formulae: [`"1,2,3,4"`],
}

sheet.insertRow(1,'')

The expected behaviour:

expect sheet.getCell('A1').dataValidation to be undefined, but it's not. And sheet.getCell('A2').dataValidation to be present, but it's undefined.

Possible solution:

If dataValidations should have the same behavior as styles, the solution can be as simple as adding

rDst.getCell(colNumber).dataValidation = cell.dataValidation;

to the spliceRows() function (similar to PR 737).

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