natergj / excel4node

Node module to allow for easy Excel file creation
MIT License
1.38k stars 215 forks source link

Date Validation is not working #207

Open pmg1407 opened 6 years ago

pmg1407 commented 6 years ago
`Sheet.addDataValidation({
        type: 'date',
        allowBlank: false,
        error: 'My Error Message',
        sqref: 'D2:D100',
        operator: 'lessThan',
        formulas: ["07/07/2018"]
    })`
natergj commented 6 years ago

Date data validation formula's require the value to be the Excel timestamp. This should work for you.

var Excel = require('excel4node');

const wb = new Excel.Workbook();
const ws = wb.addWorksheet('worksheet');

ws.addDataValidation({
    type: 'date',
    allowBlank: false,
    error: 'My Error Message',
    sqref: 'D2:D100',
    operator: 'lessThan',
    formulas: [Excel.getExcelTS(new Date("2018-07-07T00:00:00.0000Z"))]
})

ws.cell(2, 4).date(new Date("2018-07-08T00:00:00.0000Z"))
wb.write('date_validation.xlsx');
pmg1407 commented 6 years ago

Wow! It's working perfectly. Thank you so much @natergj

natergj commented 6 years ago

@pmg1407, I see that you've re-opened this issue after closing it. Are you still have issues with date validations?