Commit 2f749e6a authored by konovalovsergey's avatar konovalovsergey

for bug

fix bug 33092
parent fa76edbc
......@@ -1717,7 +1717,7 @@ cTEXT.prototype.Calculate = function ( arg ) {
var oFormat = oNumFormatCache.get( arg1.toString() );
var a = g_oFormatParser.parse(arg0.getValue()+""), aText;
aText = oFormat.format( a ? a.value : arg0.getValue(), (arg0 instanceof cNumber || a) ? CellValueType.Number : CellValueType.String, AscCommon.gc_nMaxDigCountView, null );
aText = oFormat.format( a ? a.value : arg0.getValue(), (arg0 instanceof cNumber || a) ? CellValueType.Number : CellValueType.String, AscCommon.gc_nMaxDigCountView );
var text = "";
for ( var i = 0, length = aText.length; i < length; ++i ) {
......
......@@ -5993,35 +5993,25 @@ Cell.prototype.setNumFormat=function(val){
};
Cell.prototype.shiftNumFormat=function(nShift, dDigitsCount){
var bRes = false;
var bGeneral = true;
var sNumFormat;
if(null != this.xfs && null != this.xfs.num)
sNumFormat = this.xfs.num.getFormat();
else
sNumFormat = g_oDefaultFormat.Num.getFormat();
if("General" != sNumFormat)
{
var oCurNumFormat = oNumFormatCache.get(sNumFormat);
if(null != oCurNumFormat && false == oCurNumFormat.isGeneralFormat())
{
bGeneral = false;
if (null != oCurNumFormat && false == oCurNumFormat.isGeneralFormat()) {
var output = {};
bRes = oCurNumFormat.shiftFormat(output, nShift);
if(true == bRes)
if (true == bRes) {
this.setNumFormat(output.format);
}
}
if(bGeneral)
{
if(CellValueType.Number == this.oValue.type)
{
} else if (CellValueType.Number == this.oValue.type) {
var sGeneral = AscCommon.DecodeGeneralFormat(this.oValue.number, this.oValue.type, dDigitsCount);
var oGeneral = oNumFormatCache.get(sGeneral);
if(null != oGeneral && false == oGeneral.isGeneralFormat())
{
if (null != oGeneral && false == oGeneral.isGeneralFormat()) {
var output = {};
bRes = oGeneral.shiftFormat(output, nShift);
if(true == bRes)
if (true == bRes) {
this.setNumFormat(output.format);
}
}
......
......@@ -3065,10 +3065,9 @@ CCellValue.prototype =
oNumFormat = oNumFormatCache.get(g_oDefaultFormat.Num.getFormat());
if(false == oNumFormat.isGeneralFormat())
{
var oAdditionalResult = {};
if(null != this.number)
{
aText = oNumFormat.format(this.number, this.type, dDigitsCount, oAdditionalResult);
aText = oNumFormat.format(this.number, this.type, dDigitsCount);
sText = null;
}
else if(CellValueType.String == this.type)
......@@ -3076,12 +3075,12 @@ CCellValue.prototype =
var oTextFormat = oNumFormat.getTextFormat();
if (null != oTextFormat && "@" != oTextFormat.formatString) {
if (null != this.text) {
aText = oNumFormat.format(this.text, this.type, dDigitsCount, oAdditionalResult);
aText = oNumFormat.format(this.text, this.type, dDigitsCount);
sText = null;
}
else if (null != this.multiText) {
var sSimpleString = this.getStringFromMultiText();
aText = oNumFormat.format(sSimpleString, this.type, dDigitsCount, oAdditionalResult);
aText = oNumFormat.format(sSimpleString, this.type, dDigitsCount);
sText = null;
}
}
......
......@@ -71,6 +71,7 @@ var numFormat_DecimalPointText = 22;
//Вспомогательные типы, которые заменятюся в _prepareFormat
var numFormat_MonthMinute = 101;
var numFormat_Percent = 102;
var numFormat_General = 103;
var FormatStates = {Decimal: 1, Frac: 2, Scientific: 3, Slash: 4};
var SignType = {Positive: 1, Negative: 2, Null:3};
......@@ -179,37 +180,6 @@ function FormatObjBracket(sData)
this.Lid = sSecondParam;
}
}
}
else if("y" == first || "m" == first || "d" == first || "h" == first || "s" == first ||
"Y" == first || "M" == first || "D" == first || "H" == first || "S" == first)
{
var bSame = true;
var nCount = 1;
for(var i = 1; i < length; ++i)
{
if(first != data[i])
{
bSame = false;
break;
}
nCount++;
}
if(true == bSame)
{
switch(first)
{
case "Y":
case "y": this.dataObj = new FormatObjDateVal(numFormat_Year, nCount, true);break;
case "M":
case "m": this.dataObj = new FormatObjDateVal(numFormat_MonthMinute, nCount, true);break;
case "D":
case "d": this.dataObj = new FormatObjDateVal(numFormat_Day, nCount, true);break;
case "H":
case "h": this.dataObj = new FormatObjDateVal(numFormat_Hour, nCount, true);break;
case "S":
case "s": this.dataObj = new FormatObjDateVal(numFormat_Second, nCount, true);break;
}
}
}
else if("=" == first || ">" == first || "<" == first)
{
......@@ -255,6 +225,37 @@ function FormatObjBracket(sData)
this.color = 0xffffff;
else if("yellow" == sLowerColor)
this.color = 0xffff00;
else if("y" == first || "m" == first || "d" == first || "h" == first || "s" == first ||
"Y" == first || "M" == first || "D" == first || "H" == first || "S" == first)
{
var bSame = true;
var nCount = 1;
for(var i = 1; i < length; ++i)
{
if(first != data[i])
{
bSame = false;
break;
}
nCount++;
}
if(true == bSame)
{
switch(first)
{
case "Y":
case "y": this.dataObj = new FormatObjDateVal(numFormat_Year, nCount, true);break;
case "M":
case "m": this.dataObj = new FormatObjDateVal(numFormat_MonthMinute, nCount, true);break;
case "D":
case "d": this.dataObj = new FormatObjDateVal(numFormat_Day, nCount, true);break;
case "H":
case "h": this.dataObj = new FormatObjDateVal(numFormat_Hour, nCount, true);break;
case "S":
case "s": this.dataObj = new FormatObjDateVal(numFormat_Second, nCount, true);break;
}
}
}
}
}
};
......@@ -293,7 +294,6 @@ function NumFormat(bAddMinusIfNes)
this.ComporationOperator = null;
this.bGeneralChart = false;//если в формате только один текст(например в chart "Основной")
this.bGeneral = false;//Форматирование не задано
this.bAddMinusIfNes = bAddMinusIfNes;//когда не задано форматирование для отрицательных чисел иногда надо вставлять минус
}
NumFormat.prototype =
......@@ -316,7 +316,7 @@ NumFormat.prototype =
_skip : function(val)
{
var nNewIndex = this.index + val;
if(nNewIndex >= 0 && nNewIndex < this.length)
if(nNewIndex >= 0)
this.index = nNewIndex;
},
_addToFormat : function(type, val)
......@@ -343,6 +343,10 @@ NumFormat.prototype =
}
this._addToFormat(numFormat_Text, sText);
},
_GetText : function(len)
{
return this.formatString.substr(this.index, len);
},
_ReadChar : function()
{
var next = this._readChar();
......@@ -403,6 +407,8 @@ NumFormat.prototype =
},
_parseFormat : function(format)
{
var sGeneral = AscCommon.g_cGeneralFormat.toLowerCase();
var sGeneralFirst = sGeneral[0];
this.bGeneralChart = true;
while(true)
{
......@@ -502,9 +508,15 @@ NumFormat.prototype =
this._ReadAmPm(next);
}
else {
if (sGeneralFirst === next.toLowerCase() &&
sGeneral === (next + this._GetText(sGeneral.length - 1)).toLowerCase()) {
this._addToFormat(numFormat_General);
this._skip(sGeneral.length - 1);
} else {
bNoFormat = true;
this._addToFormat(numFormat_Text, next);
}
}
if (!bNoFormat)
this.bGeneralChart = false;
}
......@@ -1341,52 +1353,39 @@ NumFormat.prototype =
}
}
},
setFormat: function (format, cultureInfo)
{
if (null == cultureInfo)
setFormat: function(format, cultureInfo) {
if (null == cultureInfo) {
cultureInfo = g_oDefaultCultureInfo;
}
this.formatString = format;
this.length = this.formatString.length;
if("general" == this.formatString.toLowerCase())
{
this.valid = true;
this.bGeneral = true;
return true;
}
else
{
//Первый проход - просто разбиваем на спецсимволы
//string -> tokens
this.valid = this._parseFormat();
if(true == this.valid)
{
//Анализируем
if (true == this.valid) {
//prepare tokens
this.valid = this._prepareFormat();
if(this.valid)
{
//проверяем типы, которые мы не определяем в _prepareFormat
var aCurrencySymbols = ["$", "", "£", "¥","р.", cultureInfo.CurrencySymbol];
if (this.valid) {
//additional prepare
var aCurrencySymbols = ["$", "", "£", "¥", "р.", cultureInfo.CurrencySymbol];
var sText = "";
for(var i = 0, length = this.aRawFormat.length; i < length; ++i)
{
for (var i = 0, length = this.aRawFormat.length; i < length; ++i) {
var item = this.aRawFormat[i];
if(numFormat_Text == item.type)
if (numFormat_Text == item.type) {
sText += item.val;
else if(numFormat_Bracket == item.type)
{
if(null != item.CurrencyString)
} else if (numFormat_Bracket == item.type) {
if (null != item.CurrencyString) {
sText += item.CurrencyString;
}
else if(numFormat_DecimalPoint == item.type)
}
else if (numFormat_DecimalPoint == item.type) {
sText += gc_sFormatDecimalPoint;
else if(numFormat_DecimalPointText == item.type)
} else if (numFormat_DecimalPointText == item.type) {
sText += gc_sFormatDecimalPoint;
}
if("" != sText)
{
for(var i = 0, length = aCurrencySymbols.length; i < length; ++i)
{
if(-1 != sText.indexOf(aCurrencySymbols[i]))
{
}
if ("" != sText) {
for (var i = 0, length = aCurrencySymbols.length; i < length; ++i) {
if (-1 != sText.indexOf(aCurrencySymbols[i])) {
this.bCurrency = true;
break;
}
......@@ -1394,23 +1393,46 @@ NumFormat.prototype =
}
var rxNumber = new RegExp("^[0#?]+(" + escapeRegExp(gc_sFormatDecimalPoint) + "[0#?]+)?$");
var match = this.formatString.match(rxNumber);
if(null != match)
{
if(null != match[1])
if (null != match) {
if (null != match[1]) {
this.bNumber = true;
else
} else {
this.bInteger = true;
}
}
}
return this.valid;
}
return this.valid;
},
isInvalidDateValue : function(number)
{
return (number == number - 0) && ((number < 0 && !AscCommon.bDate1904) || number > 2958465.9999884);
},
format: function (number, nValType, dDigitsCount, oAdditionalResult, cultureInfo, bChart)
_applyGeneralFormat: function(number, nValType, dDigitsCount, bChart, cultureInfo){
var res = null;
//todo fIsFitMeasurer and decrease dDigitsCount by other format tokens
var sGeneral = DecodeGeneralFormat(number, nValType, dDigitsCount);
if (null != sGeneral) {
var numFormat = oNumFormatCache.get(sGeneral);
if (null != numFormat) {
res = numFormat.format(number, nValType, dDigitsCount, bChart, cultureInfo, true);
}
}
if(!res){
res = [{text: number.toString()}];
}
if (-1 != this.Color) {
for (var i = 0; i < res.length; ++i) {
var elem = res[i];
if (null == elem.format) {
elem.format = new NumFormatFont();
}
elem.format.c = new AscCommonExcel.RgbColor(this.Color);
}
}
return res;
},
format: function (number, nValType, dDigitsCount, cultureInfo, bChart)
{
if (null == cultureInfo)
cultureInfo = g_oDefaultCultureInfo;
......@@ -1431,19 +1453,9 @@ NumFormat.prototype =
}
}
var oParsedNumber = this._parseNumber(number, this.aDecFormat, this.aFracFormat.length, nValType, cultureInfo);
if (true == this.bGeneral || (true == oParsedNumber.bDigit && true == this.bTextFormat) || (false == oParsedNumber.bDigit && false == this.bTextFormat) || (bChart && this.bGeneralChart))
if (true == this.isGeneral() || (true == oParsedNumber.bDigit && true == this.bTextFormat) || (false == oParsedNumber.bDigit && false == this.bTextFormat) || (bChart && this.bGeneralChart))
{
//Строим подходящий general format
if(null != oAdditionalResult)
oAdditionalResult.bGeneral = true;
var sGeneral = DecodeGeneralFormat(number, nValType, dDigitsCount);
if(null != sGeneral)
{
var numFormat = oNumFormatCache.get(sGeneral);
if(null != numFormat)
return numFormat.format(number, nValType, dDigitsCount, oAdditionalResult)
}
return [{text: number.toString()}];
return this._applyGeneralFormat(number, nValType, dDigitsCount, bChart, cultureInfo);
}
var aDec = [];
var aFrac = [];
......@@ -1747,6 +1759,11 @@ NumFormat.prototype =
for (var k = 0; k < aMilSec.length; k++)
this._AddDigItem(res, oCurText, aMilSec[k]);
}
else if (numFormat_General == item.type) {
this._CommitText(res, oCurText, null, null);
//todo minus sign
res = res.concat(this._applyGeneralFormat(Math.abs(number), nValType, dDigitsCount, bChart, cultureInfo));
}
}
this._CommitText(res, oCurText, null, null);
if(0 == res.length)
......@@ -1972,7 +1989,7 @@ NumFormat.prototype =
getType : function()
{
var nType = c_oAscNumFormatType.Custom;
if(this.bGeneral)
if(this.isGeneral())
nType = c_oAscNumFormatType.General;
else if(this.bTextFormat)
nType = c_oAscNumFormatType.Text;
......@@ -1999,7 +2016,9 @@ NumFormat.prototype =
nType = c_oAscNumFormatType.Number;
else if(this.bInteger)
nType = c_oAscNumFormatType.Integer;
return nType;
},
isGeneral: function() {
return 1 == this.aRawFormat.length && numFormat_General == this.aRawFormat[0].type;
}
};
function NumFormatCache()
......@@ -2190,9 +2209,9 @@ CellFormat.prototype =
isGeneralFormat : function()
{
if(null != this.oPositiveFormat)
return this.oPositiveFormat.bGeneral;
return this.oPositiveFormat.isGeneral();
else if(null != this.aComporationFormats && this.aComporationFormats.length > 0)
return this.aComporationFormats[0].bGeneral;
return this.aComporationFormats[0].isGeneral();
return false;
},
isDateTimeFormat : function()
......@@ -2263,14 +2282,16 @@ CellFormat.prototype =
}
return oRes;
},
format : function(number, nValType, dDigitsCount, oAdditionalResult, bChart, cultureInfo)
format : function(number, nValType, dDigitsCount, bChart, cultureInfo, opt_withoutCache)
{
var res = null;
if (null == bChart)
bChart = false;
var lcid = cultureInfo ? cultureInfo.LCID : 0;
var cacheKey = number + '-' + nValType + '-' + dDigitsCount + '-' + lcid;
var cacheVal = this.formatCache[cacheKey];
var cacheKey, cacheVal;
if (!opt_withoutCache) {
cacheKey = number + '-' + nValType + '-' + dDigitsCount + '-' + lcid;
cacheVal = this.formatCache[cacheKey];
if(null != cacheVal)
{
if (bChart)
......@@ -2280,6 +2301,7 @@ CellFormat.prototype =
if (null != res)
return res;
}
}
res = [{text: number.toString()}];
var dNumber = number - 0;
var oFormat = null;
......@@ -2287,7 +2309,7 @@ CellFormat.prototype =
{
oFormat = this.getFormatByValue(dNumber);
if(null != oFormat)
res = oFormat.format(number, nValType, dDigitsCount, oAdditionalResult, cultureInfo, bChart);
res = oFormat.format(number, nValType, dDigitsCount, cultureInfo, bChart);
else if(null != this.aComporationFormats)
{
var oNewFont = new NumFormatFont();
......@@ -2300,12 +2322,12 @@ CellFormat.prototype =
//text
if (null != this.oTextFormat) {
oFormat = this.oTextFormat;
res = oFormat.format(number, nValType, dDigitsCount, oAdditionalResult, cultureInfo, bChart);
res = oFormat.format(number, nValType, dDigitsCount, cultureInfo, bChart);
}
}
if(null == cacheVal)
{
cacheVal = { chart: null, nochart: null };
if (!opt_withoutCache) {
if (null == cacheVal) {
cacheVal = {chart: null, nochart: null};
this.formatCache[cacheKey] = cacheVal;
}
if (null != oFormat && oFormat.bGeneralChart) {
......@@ -2318,6 +2340,7 @@ CellFormat.prototype =
cacheVal.chart = res;
cacheVal.nochart = res;
}
}
return res;
},
shiftFormat : function(output, nShift)
......@@ -2961,7 +2984,7 @@ FormatParser.prototype =
sFormat = "#" + gc_sFormatThousandSeparator + "##0" + sFracFormat;
}
else
sFormat = "General";
sFormat = AscCommon.g_cGeneralFormat;
res.format = sFormat;
res.value = dVal;
}
......
......@@ -39,6 +39,7 @@
function(window, undefined)
{
var g_cCharDelimiter = String.fromCharCode(5);
var g_cGeneralFormat = 'General';
var FONT_THUMBNAIL_HEIGHT = (7 * 96.0 / 25.4) >> 0;
var c_oAscMaxColumnWidth = 255;
var c_oAscMaxRowHeight = 409;
......@@ -1418,6 +1419,7 @@
window['AscCommon'] = window['AscCommon'] || {};
window["AscCommon"].g_cCharDelimiter = g_cCharDelimiter;
window["AscCommon"].g_cGeneralFormat = g_cGeneralFormat;
window["AscCommon"].bDate1904 = false;
window["AscCommon"].c_oAscAdvancedOptionsAction = c_oAscAdvancedOptionsAction;
window["AscCommon"].DownloadType = DownloadType;
......
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