Commit bdc4855b authored by konovalovsergey's avatar konovalovsergey

asc_getLocaleExample2 for cell

parent e0543f5a
......@@ -236,11 +236,23 @@ var editor;
}
return res;
};
spreadsheet_api.prototype.asc_getLocaleExample2 = function (format, value, culture) {
spreadsheet_api.prototype.asc_getLocaleExample2 = function(format, value, culture) {
var cultureInfo = AscCommon.g_aCultureInfos[culture] || AscCommon.g_oDefaultCultureInfo;
var numFormat = AscCommon.oNumFormatCache.get(format);
value = (null == value) ? this.wb.getSelectionInfo().asc_getFormula() : value;
return numFormat.formatToChart(value, cultureInfo);
var res;
if (null == value) {
var ws = this.wbModel.getActiveWs();
var activeCell = ws.selectionRange.activeCell;
var cell = ws._getCellNoEmpty(activeCell.row, activeCell.col);
if (cell) {
res = cell.getValueForExample(numFormat, cultureInfo);
} else {
res = '';
}
} else {
res = numFormat.formatToChart(value, cultureInfo);
}
return res;
};
spreadsheet_api.prototype.asc_getFormatCells = function (info) {
......
......@@ -5084,6 +5084,10 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){
this._checkDirty();
return this.oValue.getValueForEdit2(this);
};
Cell.prototype.getValueForExample=function(numFormat, cultureInfo){
this._checkDirty();
return this.oValue.getValueForExample(this, AscCommon.gc_nMaxDigCountView, function(){return true;}, numFormat, cultureInfo);
};
Cell.prototype.getValueWithoutFormat=function(){
this._checkDirty();
return this.oValue.getValueWithoutFormat();
......
......@@ -3139,16 +3139,20 @@ CCellValue.prototype =
if(null == this.textValue)
{
this.getValue2(cell, gc_nMaxDigCountView, function(){return true;});
this.textValue = "";
var aText = this.aTextValue2[gc_nMaxDigCountView];
for(var i = 0, length = aText.length; i < length; ++i)
{
if(aText[i].format && aText[i].format.getSkip() == false)
this.textValue += aText[i].text;
}
this.textValue = this._textArrayToString(this.aTextValue2[gc_nMaxDigCountView]);
}
return this.textValue;
},
_textArrayToString: function(aText) {
var res = '';
for (var i = 0, length = aText.length; i < length; ++i) {
var elem = aText[i];
if (elem.format && elem.format.getSkip() == false) {
res += elem.text;
}
}
return res;
},
getValueForEdit : function(cell)
{
if(null == this.textValueForEdit)
......@@ -3170,73 +3174,88 @@ CCellValue.prototype =
aRes = this.aTextValue2[dDigitsCount];
if(null == aRes)
{
aRes = this._getValue2(cell, dDigitsCount, fIsFitMeasurer);
var formula = cell.getFormula();
if( formula ){
aRes[0].sFormula = formula;
aRes[0].sId = cell.getName();
}
this.aTextValue2[dDigitsCount] = aRes;
}
return aRes;
},
getValueForExample : function(cell, dDigitsCount, fIsFitMeasurer, numFormat, cultureInfo)
{
var aText = this._getValue2(cell, dDigitsCount, fIsFitMeasurer, numFormat, cultureInfo);
return this._textArrayToString(aText);
},
_getValue2: function(cell, dDigitsCount, fIsFitMeasurer, opt_numFormat, opt_cultureInfo) {
var aRes = null;
var bNeedMeasure = true;
var sText = null;
var aText = null;
if(CellValueType.Number == this.type || CellValueType.String == this.type)
{
if(null != this.text)
if (CellValueType.Number == this.type || CellValueType.String == this.type) {
if (null != this.text) {
sText = this.text;
else if(null != this.multiText)
} else if (null != this.multiText) {
aText = this.multiText;
}
if(CellValueType.String == this.type)
if (CellValueType.String == this.type) {
bNeedMeasure = false;
}
var oNumFormat;
if (opt_numFormat) {
oNumFormat = opt_numFormat;
} else {
var xfs = cell.getCompiledStyle();
if(null != xfs && null != xfs.num)
if (null != xfs && null != xfs.num) {
oNumFormat = oNumFormatCache.get(xfs.num.getFormat());
else
} else {
oNumFormat = oNumFormatCache.get(g_oDefaultFormat.Num.getFormat());
if(false == oNumFormat.isGeneralFormat())
{
if(null != this.number)
{
aText = oNumFormat.format(this.number, this.type, dDigitsCount);
sText = null;
}
else if(CellValueType.String == this.type)
{
}
if (false == oNumFormat.isGeneralFormat()) {
if (null != this.number) {
aText = oNumFormat.format(this.number, this.type, dDigitsCount, false, opt_cultureInfo);
sText = null;
} else if (CellValueType.String == this.type) {
var oTextFormat = oNumFormat.getTextFormat();
if (null != oTextFormat && "@" != oTextFormat.formatString) {
if (null != this.text) {
aText = oNumFormat.format(this.text, this.type, dDigitsCount);
aText = oNumFormat.format(this.text, this.type, dDigitsCount, false, opt_cultureInfo);
sText = null;
}
else if (null != this.multiText) {
} else if (null != this.multiText) {
var sSimpleString = this.getStringFromMultiText();
aText = oNumFormat.format(sSimpleString, this.type, dDigitsCount);
aText = oNumFormat.format(sSimpleString, this.type, dDigitsCount, false, opt_cultureInfo);
sText = null;
}
}
}
}
else if(CellValueType.Number == this.type && null != this.number)
{
} else if (CellValueType.Number == this.type && null != this.number) {
bNeedMeasure = false;
var bFindResult = false;
//варируем dDigitsCount чтобы результат влез в ячейку
var nTempDigCount = Math.ceil(dDigitsCount);
var sOriginText = this.number;
while(nTempDigCount >= 1)
{
while (nTempDigCount >= 1) {
//Строим подходящий general format
var sGeneral = AscCommon.DecodeGeneralFormat(sOriginText, this.type, nTempDigCount);
if(null != sGeneral)
if (null != sGeneral) {
oNumFormat = oNumFormatCache.get(sGeneral);
}
if(null != oNumFormat)
{
if (null != oNumFormat) {
sText = null;
aText = oNumFormat.format(sOriginText, this.type, dDigitsCount);
if(true == oNumFormat.isTextFormat())
aText = oNumFormat.format(sOriginText, this.type, dDigitsCount, false, opt_cultureInfo);
if (true == oNumFormat.isTextFormat()) {
break;
else
{
} else {
aRes = this._getValue2Result(cell, sText, aText);
//Проверяем влезает ли текст
if(true == fIsFitMeasurer(aRes))
{
if (true == fIsFitMeasurer(aRes)) {
bFindResult = true;
break;
}
......@@ -3245,52 +3264,40 @@ CCellValue.prototype =
}
nTempDigCount--;
}
if(false == bFindResult)
{
if (false == bFindResult) {
aRes = null;
sText = null;
var font = new AscCommonExcel.Font();
if (dDigitsCount > 1){
if (dDigitsCount > 1) {
font.setRepeat(true);
aText = [{ text: "#", format: font}];
}
else
aText = [{text: "#", format: font}];
} else {
aText = [{text: "", format: font}];
}
}
}
else if(CellValueType.Bool == this.type)
{
if(null != this.number)
sText = (0 != this.number) ? cBoolLocal["t"].toUpperCase(): cBoolLocal["f"].toUpperCase();
} else if (CellValueType.Bool == this.type) {
if (null != this.number) {
sText = (0 != this.number) ? cBoolLocal["t"].toUpperCase() : cBoolLocal["f"].toUpperCase();
}
else if(CellValueType.Error == this.type)
{
if(null != this.text)
} else if (CellValueType.Error == this.type) {
if (null != this.text) {
sText = this._getValueTypeError(this.text);
}
if(bNeedMeasure)
{
}
if (bNeedMeasure) {
aRes = this._getValue2Result(cell, sText, aText);
//Проверяем влезает ли текст
if(false == fIsFitMeasurer(aRes))
{
if (false == fIsFitMeasurer(aRes)) {
aRes = null;
sText = null;
var font = new AscCommonExcel.Font();
font.setRepeat(true);
aText = [{ text: "#", format: font }];
aText = [{text: "#", format: font}];
}
}
if(null == aRes)
if (null == aRes) {
aRes = this._getValue2Result(cell, sText, aText);
var formula = cell.getFormula();
if( formula ){
aRes[0].sFormula = formula;
aRes[0].sId = cell.getName();
}
this.aTextValue2[dDigitsCount] = aRes;
}
return aRes;
},
......
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