Commit 03ac22a2 authored by Alexander.Trofimov's avatar Alexander.Trofimov

support cellIs in conditions formatting

parent c3de53f7
...@@ -138,6 +138,48 @@ ...@@ -138,6 +138,48 @@
} }
return {start: start, end: end}; return {start: start, end: end};
}; };
CConditionalFormattingRule.prototype.cellIs = function(val, v1, v2) {
var res = false;
switch(this.operator) {
case AscCommonExcel.ECfOperator.Operator_beginsWith:
res = val.endsWith(v1);
break;
case AscCommonExcel.ECfOperator.Operator_between:
res = v1 <= val && val <= v2;
break;
case AscCommonExcel.ECfOperator.Operator_containsText:
res = -1 !== val.indexOf(v1);
break;
case AscCommonExcel.ECfOperator.Operator_endsWith:
res = val.startsWith(v1);
break;
case AscCommonExcel.ECfOperator.Operator_equal:
res = val == v1;
break;
case AscCommonExcel.ECfOperator.Operator_greaterThan:
res = val > v1;
break;
case AscCommonExcel.ECfOperator.Operator_greaterThanOrEqual:
res = val >= v1;
break;
case AscCommonExcel.ECfOperator.Operator_lessThan:
res = val < v1;
break;
case AscCommonExcel.ECfOperator.Operator_lessThanOrEqual:
res = val <= v1;
break;
case AscCommonExcel.ECfOperator.Operator_notBetween:
res = !(v1 <= val && val <= v2);
break;
case AscCommonExcel.ECfOperator.Operator_notContains:
res = -1 === val.indexOf(v1);
break;
case AscCommonExcel.ECfOperator.Operator_notEqual:
res = val != v1;
break;
}
return res;
};
function CColorScale () { function CColorScale () {
this.aCFVOs = []; this.aCFVOs = [];
...@@ -214,6 +256,7 @@ ...@@ -214,6 +256,7 @@
function CFormulaCF () { function CFormulaCF () {
this.Text = null; this.Text = null;
this._f = null;
return this; return this;
} }
...@@ -222,6 +265,16 @@ ...@@ -222,6 +265,16 @@
res.Text = this.Text; res.Text = this.Text;
return res; return res;
}; };
CFormulaCF.prototype.init = function(ws) {
if (!this._f) {
this._f = new AscCommonExcel.parserFormula(this.Text, '', ws);
this._f.parse();
}
};
CFormulaCF.prototype.getValue = function(ws) {
this.init(ws);
return this._f.calculate().getValue();
};
function CIconSet () { function CIconSet () {
this.IconSet = Asc.EIconSetType.Traffic3Lights1; this.IconSet = Asc.EIconSetType.Traffic3Lights1;
......
...@@ -8100,7 +8100,8 @@ ...@@ -8100,7 +8100,8 @@
window["Asc"].ETableStyleType = ETableStyleType; window["Asc"].ETableStyleType = ETableStyleType;
window["Asc"].EFontScheme = EFontScheme; window["Asc"].EFontScheme = EFontScheme;
window["Asc"].EIconSetType = EIconSetType; window["Asc"].EIconSetType = EIconSetType;
window["Asc"].ECfType = ECfType; window["AscCommonExcel"].ECfOperator = ECfOperator;
window["AscCommonExcel"].ECfType = ECfType;
window["AscCommonExcel"].ECfvoType = ECfvoType; window["AscCommonExcel"].ECfvoType = ECfvoType;
window["AscCommonExcel"].ST_TimePeriod = ST_TimePeriod; window["AscCommonExcel"].ST_TimePeriod = ST_TimePeriod;
window["Asc"].ESparklineType = ESparklineType; window["Asc"].ESparklineType = ESparklineType;
......
...@@ -3510,9 +3510,9 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) { ...@@ -3510,9 +3510,9 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) {
for (j = 0; j < aRules.length; ++j) { for (j = 0; j < aRules.length; ++j) {
oRule = aRules[j]; oRule = aRules[j];
// ToDo aboveAverage, cellIs, // ToDo aboveAverage,
// ToDo dataBar, expression, iconSet (page 2679) // ToDo dataBar, expression, iconSet (page 2679)
if (Asc.ECfType.colorScale === oRule.type) { if (AscCommonExcel.ECfType.colorScale === oRule.type) {
if (1 !== oRule.aRuleElements.length) { if (1 !== oRule.aRuleElements.length) {
break; break;
} }
...@@ -3565,7 +3565,7 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) { ...@@ -3565,7 +3565,7 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) {
value.c.setConditionalFormattingStyle(dxf); value.c.setConditionalFormattingStyle(dxf);
} }
} }
} else if (Asc.ECfType.top10 === oRule.type) { } else if (AscCommonExcel.ECfType.top10 === oRule.type) {
if (oRule.rank > 0 && oRule.dxf) { if (oRule.rank > 0 && oRule.dxf) {
nc = 0; nc = 0;
values = this._getValuesForConditionalFormatting(sqref, false); values = this._getValuesForConditionalFormatting(sqref, false);
...@@ -3599,30 +3599,30 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) { ...@@ -3599,30 +3599,30 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) {
values = this._getValuesForConditionalFormatting(sqref, true); values = this._getValuesForConditionalFormatting(sqref, true);
switch (oRule.type) { switch (oRule.type) {
case Asc.ECfType.duplicateValues: case AscCommonExcel.ECfType.duplicateValues:
case Asc.ECfType.uniqueValues: case AscCommonExcel.ECfType.uniqueValues:
o = getUniqueKeys(values); o = getUniqueKeys(values);
compareFunction = (function(obj, condition){ compareFunction = (function(obj, condition){
return function(val) { return function(val) {
return condition === obj[val]; return condition === obj[val];
}; };
})(o, oRule.type === Asc.ECfType.duplicateValues); })(o, oRule.type === AscCommonExcel.ECfType.duplicateValues);
break; break;
case Asc.ECfType.containsText: case AscCommonExcel.ECfType.containsText:
compareFunction = (function(text){ compareFunction = (function(text){
return function(val) { return function(val) {
return -1 !== val.indexOf(text); return -1 !== val.indexOf(text);
}; };
})(oRule.text); })(oRule.text);
break; break;
case Asc.ECfType.notContainsText: case AscCommonExcel.ECfType.notContainsText:
compareFunction = (function(text){ compareFunction = (function(text){
return function(val) { return function(val) {
return -1 === val.indexOf(text); return -1 === val.indexOf(text);
}; };
})(oRule.text); })(oRule.text);
break; break;
case Asc.ECfType.beginsWith: case AscCommonExcel.ECfType.beginsWith:
compareFunction = (function(text){ compareFunction = (function(text){
return function(val) { return function(val) {
return val.startsWith(text); return val.startsWith(text);
...@@ -3630,45 +3630,52 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) { ...@@ -3630,45 +3630,52 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) {
})(oRule.text); })(oRule.text);
break; break;
case Asc.ECfType.endsWith: case AscCommonExcel.ECfType.endsWith:
compareFunction = (function(text){ compareFunction = (function(text){
return function(val) { return function(val) {
return val.endsWith(text); return val.endsWith(text);
}; };
})(oRule.text); })(oRule.text);
break; break;
case Asc.ECfType.containsErrors: case AscCommonExcel.ECfType.containsErrors:
compareFunction = function(val, c) { compareFunction = function(val, c) {
return CellValueType.Error === c.getType(); return CellValueType.Error === c.getType();
}; };
break; break;
case Asc.ECfType.notContainsErrors: case AscCommonExcel.ECfType.notContainsErrors:
compareFunction = function(val, c) { compareFunction = function(val, c) {
return CellValueType.Error !== c.getType(); return CellValueType.Error !== c.getType();
}; };
break; break;
case Asc.ECfType.containsBlanks: case AscCommonExcel.ECfType.containsBlanks:
compareFunction = function(val, c) { compareFunction = function(val, c) {
return c.isEmptyTextString(); return c.isEmptyTextString();
}; };
break; break;
case Asc.ECfType.notContainsBlanks: case AscCommonExcel.ECfType.notContainsBlanks:
compareFunction = function(val, c) { compareFunction = function(val, c) {
return !c.isEmptyTextString(); return !c.isEmptyTextString();
}; };
break; break;
case Asc.ECfType.timePeriod: case AscCommonExcel.ECfType.timePeriod:
if (oRule.timePeriod) { if (oRule.timePeriod) {
compareFunction = (function(rule, period) { compareFunction = (function(period) {
return function(val, c) { return function(val, c) {
var n = parseFloat(val); var n = parseFloat(val);
return period.start <= n && n <= period.end; return period.start <= n && n <= period.end;
}; };
})(oRule, oRule.getTimePeriod()); })(oRule.getTimePeriod());
} else { } else {
continue; continue;
} }
break; break;
case AscCommonExcel.ECfType.cellIs:
compareFunction = (function(rule, v1, v2) {
return function(val, c) {
return rule.cellIs(val, v1, v2);
};
})(oRule, oRule.aRuleElements[0] && oRule.aRuleElements[0].getValue(this), oRule.aRuleElements[1] && oRule.aRuleElements[1].getValue(this));
break;
default: default:
continue; continue;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment