Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Add data validity
Browse files Browse the repository at this point in the history
Providing dropdown list validation
Example: 
ws.setValidation({
    type: "list",
    allowBlank: 1,
    showInputMessage: 1,
    showErrorMessage: 1,
    sqref: "X2:X10",
    formulas: [
      'value1,value2'
    ]
  });
  • Loading branch information
atsapenko committed Feb 24, 2015
1 parent 39c03da commit 37fcd6c
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lib/WorkSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ WorkSheet.prototype.Image = Image.Image;
WorkSheet.prototype.getCell = getCell;
WorkSheet.prototype.setWSOpts = setWSOpts;
WorkSheet.prototype.toXML = toXML;
WorkSheet.prototype.setValidation = setValidation;

var countValidation = 0;
function setValidation(data) {
countValidation++;
this.sheet.dataValidations = this.sheet.dataValidations || {};
this.sheet.dataValidations['@count'] = countValidation;

this.sheet.dataValidations['#list'] = this.sheet.dataValidations['#list'] || [];
var dataValidation = {};
Object.keys(data).forEach(function (key) {
if (key == 'formulas') { return; }

dataValidation['@' + key] = data[key];
});
data.formulas.forEach(function (f, i) {
f = typeof f == 'number' ? f : '"' + f + '"';
dataValidation['formula' + (i + 1)] = f;
});
this.sheet.dataValidations['#list'].push({
dataValidation: dataValidation
});
}


function getCell(a,b){
var props = {};
Expand Down Expand Up @@ -301,6 +325,7 @@ function toXML(){
'sheetData',
'autoFilter',
'mergeCells',
'dataValidations',
'printOptions',
'pageMargins',
'drawing'
Expand All @@ -326,4 +351,4 @@ function toXML(){
}


module.exports = WorkSheet;
module.exports = WorkSheet;

0 comments on commit 37fcd6c

Please sign in to comment.