Commit 6ae175a7 authored by Alexander.Trofimov's avatar Alexander.Trofimov

add function in range getValues and getValuesAndMap

fix bug 32608
parent d60a72dc
...@@ -3532,17 +3532,8 @@ Woorksheet.prototype.initPostOpen = function(handlers){ ...@@ -3532,17 +3532,8 @@ Woorksheet.prototype.initPostOpen = function(handlers){
this._setHandlersTablePart(); this._setHandlersTablePart();
}; };
Woorksheet.prototype._getValuesForConditionalFormatting = function(sqref, withEmpty) { Woorksheet.prototype._getValuesForConditionalFormatting = function(sqref, withEmpty) {
var res = [];
var range = this.getRange3(sqref.r1, sqref.c1, sqref.r2, sqref.c2); var range = this.getRange3(sqref.r1, sqref.c1, sqref.r2, sqref.c2);
var fAction = function(c) { return range._getValues(withEmpty);
res.push({c: c, v: c.getValueWithoutFormat()});
};
if (withEmpty) {
range._setProperty(null, null, fAction);
} else {
range._setPropertyNoEmpty(null, null, fAction);
}
return res;
}; };
Woorksheet.prototype._updateConditionalFormatting = function(range) { Woorksheet.prototype._updateConditionalFormatting = function(range) {
var oGradient1, oGradient2; var oGradient1, oGradient2;
...@@ -6506,6 +6497,32 @@ Range.prototype._getRangeType=function(oBBox){ ...@@ -6506,6 +6497,32 @@ Range.prototype._getRangeType=function(oBBox){
oBBox = this.bbox; oBBox = this.bbox;
return getRangeType(oBBox); return getRangeType(oBBox);
}; };
Range.prototype._getValues = function (withEmpty) {
var res = [];
var fAction = function(c) {
res.push({c: c, v: c.getValueWithoutFormat()});
};
if (withEmpty) {
this._setProperty(null, null, fAction);
} else {
this._setPropertyNoEmpty(null, null, fAction);
}
return res;
};
Range.prototype._getValuesAndMap = function (withEmpty) {
var v, arrRes = [], mapRes = {};
var fAction = function(c) {
v = c.getValueWithoutFormat();
arrRes.push({c: c, v: v});
mapRes[v.toLowerCase()] = true;
};
if (withEmpty) {
this._setProperty(null, null, fAction);
} else {
this._setPropertyNoEmpty(null, null, fAction);
}
return {values: arrRes, map: mapRes};
};
Range.prototype._setProperty=function(actionRow, actionCol, actionCell){ Range.prototype._setProperty=function(actionRow, actionCol, actionCell){
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
if(c_oRangeType.Range == nRangeType) if(c_oRangeType.Range == nRangeType)
......
...@@ -4044,36 +4044,49 @@ ...@@ -4044,36 +4044,49 @@
return result; return result;
}, },
_generateColumnNameWithoutTitle: function(range) _generateColumnNameWithoutTitle: function(ref)
{ {
var worksheet = this.worksheet; var tableColumns = [], newTableColumn;
var newTableColumn; var range = this.worksheet.getRange3(ref.r1, ref.c1, ref.r1, ref.c2);
var tableColumns = []; var defaultName = 'Column';
var cell; var uniqueColumns = {}, val, valTemplate, valLower, index = 1, isDuplicate = false, emptyCells = false;
var val; var valuesAndMap = range._getValuesAndMap(true);
for(var col1 = range.c1; col1 <= range.c2; col1++) var values = valuesAndMap.values;
{ var length = values.length;
cell = worksheet.getCell3(range.r1, col1); if (0 === length) {
val = cell.getValue(); // Выделили всю строку без значений
//если ячейка пустая, то генерируем название length = ref.c2 - ref.c1 + 1;
if(val == '') emptyCells = true;
val = this._generateColumnName(tableColumns); }
//проверяем, не повторяется ли значение, которое лежит в данной ячейке var map = valuesAndMap.map;
var index = 2; for (var i = 0; i < length; ++i) {
var valNew = val; if (emptyCells || '' === (valTemplate = val = values[i].v)) {
for(var s = 0; s < tableColumns.length; s++) valTemplate = defaultName;
{ val = valTemplate + index;
if(valNew == tableColumns[s].Name) ++index;
{ }
valNew = val + index;
index++; while(true) {
s = -1; if (isDuplicate) {
val = valTemplate + (++index);
}
valLower = val.toLowerCase();
if (uniqueColumns[valLower]) {
isDuplicate = true;
} else {
if (isDuplicate && map[valLower]) {
continue;
}
uniqueColumns[valLower] = true;
newTableColumn = new AscCommonExcel.TableColumn();
newTableColumn.Name = val;
tableColumns.push(newTableColumn);
isDuplicate = false;
break;
} }
} }
newTableColumn = new AscCommonExcel.TableColumn();
newTableColumn.Name = valNew;
tableColumns[col1 - range.c1] = newTableColumn;
} }
return tableColumns; return tableColumns;
}, },
......
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