Commit 0e04bf2a authored by Alexander.Trofimov's avatar Alexander.Trofimov

support endsWith and beginsWith in conditional formatting

parent a6db9cd2
...@@ -939,7 +939,8 @@ ...@@ -939,7 +939,8 @@
notContainsText: 13, notContainsText: 13,
timePeriod: 14, timePeriod: 14,
top10: 15, top10: 15,
uniqueValues: 16 uniqueValues: 16,
endsWith: 17
}; };
/** @enum */ /** @enum */
var EIconSetType = var EIconSetType =
......
...@@ -3496,7 +3496,7 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) { ...@@ -3496,7 +3496,7 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) {
var aRules, oRule; var aRules, oRule;
var oRuleElement = null; var oRuleElement = null;
var o; var o;
var i, j, cell, sqref, values, tmp, min, max, dxf, condition; var i, j, cell, sqref, values, tmp, min, max, dxf, compareFunction;
for (i = 0; i < aCFs.length; ++i) { for (i = 0; i < aCFs.length; ++i) {
sqref = aCFs[i].sqref; sqref = aCFs[i].sqref;
// ToDo убрать null === sqref когда научимся мультиселект обрабатывать (\\192.168.5.2\source\DOCUMENTS\XLSX\Matematika Quantum Sedekah.xlsx) // ToDo убрать null === sqref когда научимся мультиселект обрабатывать (\\192.168.5.2\source\DOCUMENTS\XLSX\Matematika Quantum Sedekah.xlsx)
...@@ -3511,65 +3511,95 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) { ...@@ -3511,65 +3511,95 @@ Woorksheet.prototype._updateConditionalFormatting = function(range) {
// ToDo aboveAverage, beginsWith, cellIs, containsBlanks, containsErrors, // ToDo aboveAverage, beginsWith, cellIs, containsBlanks, containsErrors,
// ToDo dataBar, endsWith, expression, iconSet, notContainsBlanks, // ToDo dataBar, endsWith, expression, iconSet, notContainsBlanks,
// ToDo notContainsErrors, timePeriod, top10 (page 2679) // ToDo notContainsErrors, timePeriod, top10 (page 2679)
switch (oRule.type) { if (Asc.ECfType.colorScale === oRule.type) {
case Asc.ECfType.colorScale: if (1 !== oRule.aRuleElements.length) {
if (1 !== oRule.aRuleElements.length) { break;
break; }
} oRuleElement = oRule.aRuleElements[0];
oRuleElement = oRule.aRuleElements[0]; if (!(oRuleElement instanceof AscCommonExcel.CColorScale)) {
if (!(oRuleElement instanceof AscCommonExcel.CColorScale)) { break;
break; }
} min = Number.MAX_VALUE;
min = Number.MAX_VALUE; max = -Number.MAX_VALUE;
max = -Number.MAX_VALUE; values = this._getValuesForConditionalFormatting(sqref);
values = this._getValuesForConditionalFormatting(sqref); for (cell = 0; cell < values.v.length; ++cell) {
for (cell = 0; cell < values.v.length; ++cell) { if (CellValueType.Number === values.c[cell].getType() && !isNaN(tmp = parseFloat(values.v[cell]))) {
if (CellValueType.Number === values.c[cell].getType() && !isNaN(tmp = parseFloat(values.v[cell]))) { values.v[cell] = tmp;
values.v[cell] = tmp; min = Math.min(min, tmp);
min = Math.min(min, tmp); max = Math.max(max, tmp);
max = Math.max(max, tmp); } else {
} else { values.v[cell] = null;
values.v[cell] = null;
}
} }
}
// ToDo CFVO Type (formula, max, min, num, percent, percentile) (page 2681) // ToDo CFVO Type (formula, max, min, num, percent, percentile) (page 2681)
// ToDo support 3 colors in rule // ToDo support 3 colors in rule
if (0 < values.c.length && 2 === oRuleElement.aColors.length) { if (0 < values.c.length && 2 === oRuleElement.aColors.length) {
oGradient = new AscCommonExcel.CGradient(oRuleElement.aColors[0], oRuleElement.aColors[1]); oGradient = new AscCommonExcel.CGradient(oRuleElement.aColors[0], oRuleElement.aColors[1]);
oGradient.init(min, max); oGradient.init(min, max);
for (cell = 0; cell < values.c.length; ++cell) { for (cell = 0; cell < values.c.length; ++cell) {
dxf = null; dxf = null;
if (null !== values.v[cell]) { if (null !== values.v[cell]) {
dxf = new AscCommonExcel.CellXfs(); dxf = new AscCommonExcel.CellXfs();
dxf.fill = new AscCommonExcel.Fill({bg: oGradient.calculateColor(values.v[cell])}); dxf.fill = new AscCommonExcel.Fill({bg: oGradient.calculateColor(values.v[cell])});
}
values.c[cell].setConditionalFormattingStyle(dxf);
} }
values.c[cell].setConditionalFormattingStyle(dxf);
} }
break; }
case Asc.ECfType.duplicateValues: } else {
case Asc.ECfType.uniqueValues: if (!oRule.dxf) {
if (oRule.dxf) { continue;
condition = oRule.type === Asc.ECfType.uniqueValues; }
values = this._getValuesForConditionalFormatting(sqref); values = this._getValuesForConditionalFormatting(sqref);
switch (oRule.type) {
case Asc.ECfType.duplicateValues:
case Asc.ECfType.uniqueValues:
o = getUniqueKeys(values.v); o = getUniqueKeys(values.v);
for (cell = 0; cell < values.c.length; ++cell) { compareFunction = (function(obj, condition){
values.c[cell].setConditionalFormattingStyle((condition === o[values.v[cell]]) ? null : oRule.dxf); return function(val) {
} return condition === obj[val];
} };
break; })(o, oRule.type === Asc.ECfType.duplicateValues);
case Asc.ECfType.containsText: break;
case Asc.ECfType.notContainsText: case Asc.ECfType.containsText:
if (oRule.dxf) { compareFunction = (function(text){
condition = oRule.type === Asc.ECfType.containsText; return function(val) {
values = this._getValuesForConditionalFormatting(sqref); return -1 !== val.indexOf(text);
for (cell = 0; cell < values.c.length; ++cell) { };
values.c[cell].setConditionalFormattingStyle((condition === (-1 === values.v[cell].indexOf(oRule.text))) ? null : oRule.dxf); })(oRule.text);
} break;
} case Asc.ECfType.notContainsText:
break; compareFunction = (function(text){
return function(val) {
return -1 === val.indexOf(text);
};
})(oRule.text);
break;
case Asc.ECfType.beginsWith:
compareFunction = (function(text){
return function(val) {
return val.startsWith(text);
};
})(oRule.text);
break;
case Asc.ECfType.endsWith:
compareFunction = (function(text){
return function(val) {
return val.endsWith(text);
};
})(oRule.text);
break;
default:
continue;
break;
}
for (cell = 0; cell < values.c.length; ++cell) {
values.c[cell].setConditionalFormattingStyle(compareFunction(values.v[cell]) ? oRule.dxf : null);
}
} }
} }
} }
......
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