I’m populating an existing Excel file using ExcelJS.
Setting the value directly, without re-adding the dataValidation
wipes out the dropdown. It’s necessary to re-add the validations again using the code below (for example):
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.load(buffer);
const targetSheet = workbook.worksheets[1];
let row = targetSheet.getRow(rowNumber); // Target row
cell = row.getCell(4); // Target cell
cell.dataValidation = {
type: 'list',
allowBlank: false,
formulae: ['"Option1,Option2,Option3"']
};
Now, I also need to read the existing dropdown values before setting the new value but using cell.dataValidation
does not work to read the current dataValidation
, but strangely it works to write them.
How to read the existing dataValidation
of a specific cell using ExcelJS?