Commit a4315b72 authored by konovalovsergey's avatar konovalovsergey

conditionalFormating sqref ranges

parent 993d18d8
......@@ -48,23 +48,32 @@
*/
function CConditionalFormatting () {
this.pivot = false;
this.sqref = null;
this.ranges = null;
this.aRules = [];
return this;
}
CConditionalFormatting.prototype.setSqref = function(sqref) {
this.sqref = AscCommonExcel.g_oRangeCache.getAscRange(sqref);
this.ranges = AscCommonExcel.g_oRangeCache.getActiveRangesFromSqRef(sqref);
};
CConditionalFormatting.prototype.clone = function() {
var i, res = new CConditionalFormatting();
res.pivot = this.pivot;
res.sqref = this.sqref ? this.sqref.clone() : null;
if (this.ranges) {
res.ranges = [];
for (var i = 0; i < this.ranges; ++i) {
res.ranges.push(this.ranges[i].clone());
}
}
for (i = 0; i < this.aRules.length; ++i)
res.aRules.push(this.aRules[i].clone());
return res;
};
CConditionalFormatting.prototype.isValid = function() {
//todo more checks
return this.ranges && this.ranges.length > 0;
}
function CConditionalFormattingRule () {
this.aboveAverage = true;
......
......@@ -1116,6 +1116,14 @@
return output;
}
function getSqRefString(ranges) {
var refs = [];
for (var i = 0; i < ranges.length; ++i) {
refs.push(ranges[i].getName());
}
return refs.join(' ');
}
/** @constructor */
function BinaryTableWriter(memory, aDxfs, isCopyPaste)
{
......@@ -2645,11 +2653,7 @@
}
//this.bs.WriteItem(c_oSer_Selection.Pane, function(){oThis.memory.WriteByte();});
if (null != selectionRange.ranges) {
var refs = [];
for (var i = 0; i < selectionRange.ranges.length; ++i) {
refs.push(selectionRange.ranges[i].getName());
}
var sqref = refs.join(' ');
var sqref = getSqRefString(selectionRange.ranges);
this.bs.WriteItem(c_oSer_Selection.Sqref, function(){oThis.memory.WriteString3(sqref);});
}
};
......@@ -3646,8 +3650,9 @@
if (null != oCf.pivot) {
this.bs.WriteItem(c_oSer_ConditionalFormatting.Pivot, function() {oThis.memory.WriteBool(oCf.pivot);});
}
if (null != oCf.sqref) {
this.bs.WriteItem(c_oSer_ConditionalFormatting.SqRef, function() {oThis.memory.WriteString3(oCf.sqref.getName());});
if (null != oCf.ranges) {
var sqref = getSqRefString(oCf.ranges);
this.bs.WriteItem(c_oSer_ConditionalFormatting.SqRef, function() {oThis.memory.WriteString3(sqref);});
}
for (var i = 0; i < oCf.aRules.length; ++i) {
this.bs.WriteItem(c_oSer_ConditionalFormatting.ConditionalFormattingRule, function() {oThis.WriteConditionalFormattingRule(oCf.aRules[i]);});
......@@ -5740,7 +5745,9 @@
res = this.bcr.Read1(length, function (t, l) {
return oThis.ReadConditionalFormatting(t, l, oConditionalFormatting);
});
oWorksheet.aConditionalFormatting.push(oConditionalFormatting);
if (oConditionalFormatting.isValid()) {
oWorksheet.aConditionalFormatting.push(oConditionalFormatting);
}
} else if (c_oSerWorksheetsTypes.SheetViews === type) {
res = this.bcr.Read1(length, function (t, l) {
return oThis.ReadSheetViews(t, l, oWorksheet.sheetViews);
......@@ -6718,17 +6725,9 @@
selectionRange.activeCellId = this.stream.GetLong();
} else if (c_oSer_Selection.Sqref === type) {
var sqref = this.stream.GetString2LE(length);
var refs = sqref.split(' ');
var selectionOld = selectionRange.ranges;
selectionRange.ranges = [];
for (var i = 0; i < refs.length; ++i) {
var ref = AscCommonExcel.g_oRangeCache.getAscRange(refs[i]);
if (ref) {
selectionRange.ranges.push(ref.clone());
}
}
if (selectionRange.ranges.length === 0) {
selectionRange.ranges = selectionOld;
var selectionNew = AscCommonExcel.g_oRangeCache.getActiveRangesFromSqRef(sqref);
if (selectionNew.length > 0) {
selectionRange.ranges = selectionNew;
}
} else if (c_oSer_Selection.Pane === type) {
this.stream.GetUChar();
......
......@@ -2670,9 +2670,22 @@
this.handlers = handlers;
this._setHandlersTablePart();
};
Woorksheet.prototype._getValuesForConditionalFormatting = function(sqref, withEmpty) {
var range = this.getRange3(sqref.r1, sqref.c1, sqref.r2, sqref.c2);
return range._getValues(withEmpty);
Woorksheet.prototype._getValuesForConditionalFormatting = function(ranges, withEmpty) {
var res = [];
for (var i = 0; i < ranges.length; ++i) {
var elem = ranges[i];
var range = this.getRange3(elem.r1, elem.c1, elem.r2, elem.c2);
res = res.concat(range._getValues(withEmpty));
}
return res;
};
Woorksheet.prototype._isConditionalFormattingIntersect = function(range, ranges) {
for (var i = 0; i < ranges.length; ++i) {
if (range.isIntersect(ranges[i])) {
return true;
}
}
return false;
};
Woorksheet.prototype._updateConditionalFormatting = function(range) {
var oGradient1, oGradient2;
......@@ -2680,15 +2693,16 @@
var aRules, oRule;
var oRuleElement = null;
var o;
var i, j, l, cell, sqref, values, value, v, tmp, min, mid, max, dxf, compareFunction, nc, sum;
var i, j, l, cf, cell, ranges, values, value, v, tmp, min, mid, max, dxf, compareFunction, nc, sum;
for (i = 0; i < aCFs.length; ++i) {
sqref = aCFs[i].sqref;
cf = aCFs[i]
ranges = cf.ranges;
// ToDo убрать null === sqref когда научимся мультиселект обрабатывать (\\192.168.5.2\source\DOCUMENTS\XLSX\Matematika Quantum Sedekah.xlsx)
if (null === sqref) {
if (!cf.isValid()) {
continue;
}
if (!range || range.isIntersect(sqref)) {
aRules = aCFs[i].aRules.sort(function(v1, v2) {
if (!range || this._isConditionalFormattingIntersect(range, ranges)) {
aRules = cf.aRules.sort(function(v1, v2) {
return v1.priority - v2.priority;
});
if (oRule = aRules[0]) {
......@@ -2704,7 +2718,7 @@
nc = 0;
min = Number.MAX_VALUE;
max = -Number.MAX_VALUE;
values = this._getValuesForConditionalFormatting(sqref, false);
values = this._getValuesForConditionalFormatting(ranges, false);
for (cell = 0; cell < values.length; ++cell) {
value = values[cell];
if (CellValueType.Number === value.c.getType() && !isNaN(tmp = parseFloat(value.v))) {
......@@ -2749,7 +2763,7 @@
} else if (AscCommonExcel.ECfType.top10 === oRule.type) {
if (oRule.rank > 0 && oRule.dxf) {
nc = 0;
values = this._getValuesForConditionalFormatting(sqref, false);
values = this._getValuesForConditionalFormatting(ranges, false);
o = oRule.bottom ? -Number.MAX_VALUE : Number.MAX_VALUE;
for (cell = 0; cell < values.length; ++cell) {
value = values[cell];
......@@ -2777,7 +2791,7 @@
if (!oRule.dxf) {
continue;
}
values = this._getValuesForConditionalFormatting(sqref, false);
values = this._getValuesForConditionalFormatting(ranges, false);
sum = 0;
nc = 0;
for (cell = 0; cell < values.length; ++cell) {
......@@ -2813,7 +2827,7 @@
if (!oRule.dxf) {
continue;
}
values = this._getValuesForConditionalFormatting(sqref, true);
values = this._getValuesForConditionalFormatting(ranges, true);
switch (oRule.type) {
case AscCommonExcel.ECfType.duplicateValues:
......
......@@ -1339,6 +1339,17 @@
RangeCache.prototype.getActiveRange = function (sRange) {
return this._getRange(sRange, 2);
};
RangeCache.prototype.getActiveRangesFromSqRef = function (sqRef) {
var res = [];
var refs = sqRef.split(' ');
for (var i = 0; i < refs.length; ++i) {
var ref = AscCommonExcel.g_oRangeCache.getAscRange(refs[i]);
if (ref) {
res.push(ref.clone());
}
}
return res;
};
RangeCache.prototype.getFormulaRange = function (sRange) {
return this._getRange(sRange, 3);
};
......
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