Search code examples
node.jsexceljs

Exceljs data validation not assigned correctly


So I'm trying to add data validations to a range of rows in a particular column with the code -

const questionTypeOptions = 'AA2:AJ2';
this.addDataValidation(sheet, questionTypeOptions, 'C3:C9999');
addDataValidation(sheet: Worksheet, options: string, cellRange: string){
    (sheet as any).dataValidations.add(cellRange, {
      type: 'list',
      allowBlank: false,
      showErrorMessage: true,
      formulae: [`${options}`],
      error: 'Please select any value from dropdown',
    });
  }

So I want to create a dropdown in excel by taking the values in that cell range. Now it should be assigning data validation of each cell from C3 to C9999 as range from AA2:AJ2. So this works fine from the 3rd cell (C3) i get the desired dropdown. But for 4th cell (C4) it assigns AA3:AJ3, then for 5th AA4:AJ4.

Couldn't find anything online related to this.

The cell is from row 4 The cell selected is from row 3


Solution

  • use absolute reference:

    const questionTypeOptions = '$AA$2:$AJ$2';