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