Commit 84c1aa29 authored by konovalovsergey's avatar konovalovsergey Committed by Alexander.Trofimov

fix bug 31395

parent a4417d30
......@@ -341,101 +341,7 @@ var editor;
if (!cultureInfo) {
cultureInfo = AscCommon.g_aCultureInfos[1033];
}
var prefixs = ['_ ', '_-', '_(', '_)'];
var prefix = prefixs[0];
var postfix = prefixs[0];
var numberFormat = '#,##0.00';
var nullSignFormat = '* "-"??';
var positiveNumberFormat = '* ' + numberFormat;
var signCurrencyFormat = '[$' + cultureInfo.CurrencySymbol + '-' + cultureInfo.LCID.toString(16).toUpperCase() + ']';
var positiveFormat;
var negativeFormat;
var nullFormat;
switch (cultureInfo.CurrencyNegativePattern) {
case 0:
prefix = prefixs[2];
postfix = prefixs[3];
negativeFormat = prefix + signCurrencyFormat + '* \\(' + numberFormat + '\\)';
break;
case 1:
prefix = postfix = prefixs[1];
negativeFormat = '\\-' + signCurrencyFormat + '* ' + numberFormat + postfix;
break;
case 2:
negativeFormat = prefix + signCurrencyFormat + '\\ * \\-' + numberFormat + postfix;
break;
case 3:
prefix = postfix = prefixs[1];
negativeFormat = prefix + signCurrencyFormat + '\\ * ' + numberFormat + '\\-';
break;
case 4:
prefix = prefixs[2];
postfix = prefixs[3];
negativeFormat = prefix + '* \\(' + numberFormat + '\\)' + signCurrencyFormat + postfix;
break;
case 5:
prefix = postfix = prefixs[1];
negativeFormat = '\\-* ' + numberFormat + signCurrencyFormat + postfix;
break;
case 6:
negativeFormat = prefix + '* ' + numberFormat + '\\-' + signCurrencyFormat + postfix;
break;
case 7:
negativeFormat = prefix + '* ' + numberFormat + signCurrencyFormat + '\\-';
break;
case 8:
prefix = postfix = prefixs[1];
negativeFormat = '\\-* ' + numberFormat + '\\ ' + signCurrencyFormat + postfix;
break;
case 9:
prefix = postfix = prefixs[1];
negativeFormat = '\\-' + signCurrencyFormat + '\\ * ' + numberFormat + postfix;
break;
case 10:
negativeFormat = prefix + '* ' + numberFormat + '\\ ' + signCurrencyFormat + '\\-';
break;
case 11:
negativeFormat = prefix + signCurrencyFormat + '\\ * ' + numberFormat + '\\-';
break;
case 12:
negativeFormat = prefix + signCurrencyFormat + '\\ * \\-' + numberFormat + postfix;
break;
case 13:
negativeFormat = prefix + '* ' + numberFormat + '\\-\\ ' + signCurrencyFormat + postfix;
break;
case 14:
prefix = prefixs[2];
postfix = prefixs[3];
negativeFormat = prefix + signCurrencyFormat + '\\ * \\(' + numberFormat + '\\)';
break;
case 15:
prefix = prefixs[2];
postfix = prefixs[3];
negativeFormat = prefix + '* \\(' + numberFormat + '\\)\\ ' + signCurrencyFormat + postfix;
break;
}
switch (cultureInfo.CurrencyPositivePattern) {
case 0:
positiveFormat = signCurrencyFormat + positiveNumberFormat;
nullFormat = signCurrencyFormat + nullSignFormat;
break;
case 1:
positiveFormat = positiveNumberFormat + signCurrencyFormat;
nullFormat = nullSignFormat + signCurrencyFormat;
break;
case 2:
positiveFormat = signCurrencyFormat + '\\ ' + positiveNumberFormat;
nullFormat = signCurrencyFormat + '\\ ' + nullSignFormat;
break;
case 3:
positiveFormat = positiveNumberFormat + '\\ ' + signCurrencyFormat;
nullFormat = nullSignFormat + '\\ ' + signCurrencyFormat;
break;
}
positiveFormat = prefix + positiveFormat + postfix;
nullFormat = prefix + nullFormat + postfix;
var textFormat = prefix + '@' + postfix;
return positiveFormat + ';' + negativeFormat + ';' + nullFormat + ';' + textFormat;
return AscCommonExcel.getCurrencyFormat(cultureInfo, true, true, true);
};
spreadsheet_api.prototype.asc_setLocale = function(val) {
if (!this.isLoadFullApi) {
......
......@@ -1610,7 +1610,7 @@
{
var dxf = this.aDxfs[i];
if(dxf && dxf.num)
oDxfsNumFormatToId[dxf.num.f] = this.oBinaryWorksheetsTableWriter.getNumIdByFormat(dxf.num);
oDxfsNumFormatToId[dxf.num.getFormat()] = this.oBinaryWorksheetsTableWriter.getNumIdByFormat(dxf.num);
}
this.bs.WriteItem(c_oSerStylesTypes.Dxfs, function(){oThis.WriteDxfs(oThis.aDxfs, oDxfsNumFormatToId);});
}
......@@ -1826,7 +1826,7 @@
{
var num = this.oNumMap[i];
if(false == num.val.isEqual(g_oDefaultFormat.NumAbs))
this.bs.WriteItem(c_oSerStylesTypes.NumFmt, function(){oThis.WriteNum({id: num.index, f: num.val.f});});
this.bs.WriteItem(c_oSerStylesTypes.NumFmt, function(){oThis.WriteNum({id: num.index, f: num.val.getFormat()});});
}
};
this.WriteNum = function(num)
......@@ -2028,9 +2028,9 @@
this.bs.WriteItem(c_oSer_Dxf.Font, function(){oThis.WriteFont(Dxf.font);});
if(null != Dxf.num && null != oDxfsNumFormatToId)
{
var numId = oDxfsNumFormatToId[Dxf.num.f];
var numId = oDxfsNumFormatToId[Dxf.num.getFormat()];
if(null != numId)
this.bs.WriteItem(c_oSer_Dxf.NumFmt, function(){oThis.WriteNum({id: numId, f: Dxf.num.f});});
this.bs.WriteItem(c_oSer_Dxf.NumFmt, function(){oThis.WriteNum({id: numId, f: Dxf.num.getFormat()});});
}
};
this.WriteCellStyles = function (cellStyles) {
......@@ -3167,27 +3167,30 @@
return sStyle;
};
this.getNumIdByFormat = function(num)
{
var numid = null;
//стандартные форматы не записываем в map, на них можно ссылаться по id
var nStandartId = AscCommonExcel.aStandartNumFormatsId[num.f];
if(null == nStandartId)
{
var sHash = this._getStringFromObjWithProperty(num);
var elem = this.oNumMap[sHash];
if(null == elem)
{
numid = this.nNumMapIndex++;
this.oNumMap[sHash] = {index: numid, val: num};
}
else
numid = elem.index;
}
else
numid = nStandartId;
return numid;
};
this.getNumIdByFormat = function(num) {
var numid = null;
//стандартные форматы не записываем в map, на них можно ссылаться по id
var nStandartId;
if (null != num.id) {
nStandartId = num.id;
} else {
nStandartId = AscCommonExcel.aStandartNumFormatsId[num.getFormat()];
}
if (null == nStandartId) {
var sHash = this._getStringFromObjWithProperty(num);
var elem = this.oNumMap[sHash];
if (null == elem) {
numid = this.nNumMapIndex++;
this.oNumMap[sHash] = {index: numid, val: num};
} else {
numid = elem.index;
}
} else {
numid = nStandartId;
}
return numid;
};
this.prepareXfs = function(xfs)
{
var nXfsId = 0;
......@@ -4658,44 +4661,32 @@
if(null != xfs.align && g_oDefaultFormat.AlignAbs.isEqual(xfs.align))
xfs.align = null;
};
this.ParseNum = function(oNum, oNumFmts)
{
var oRes = null;
var sFormat = null;
if(null != oNum && null != oNum.f)
sFormat = oNum.f;
else
{
if(5 <= oNum.id && oNum.id <= 8)
{
//В спецификации нет стилей для чисел 5-8, экспериментально установлено, что это денежный формат, зависящий от локали.
//Устанавливаем как в Engilsh(US)
switch(oNum.id)
{
case 5: sFormat = "$#,##0_);($#,##0)";break;
case 6: sFormat = "$#,##0_);[Red]($#,##0)";break;
case 7: sFormat = "$#,##0.00_);($#,##0.00)";break;
case 8: sFormat = "$#,##0.00_);[Red]($#,##0.00)";break;
}
}
else
{
var sStandartNumFormat = AscCommonExcel.aStandartNumFormats[oNum.id];
if(null != sStandartNumFormat)
sFormat = sStandartNumFormat;
}
if(null == sFormat)
sFormat = "General";
if(null != oNumFmts)
oNumFmts[oNum.id] = {id:oNum.id, f: sFormat};
}
if(null != sFormat)
{
oRes = new AscCommonExcel.Num();
oRes.f = sFormat;
}
return oRes;
};
this.ParseNum = function(oNum, oNumFmts) {
var oRes = null;
var sFormat = null;
if (null != oNum && null != oNum.f) {
sFormat = oNum.f;
} else {
var sStandartNumFormat = AscCommonExcel.aStandartNumFormats[oNum.id];
if (null != sStandartNumFormat) {
sFormat = sStandartNumFormat;
}
if (null == sFormat) {
sFormat = "General";
}
if (null != oNumFmts) {
oNumFmts[oNum.id] = {id: oNum.id, f: sFormat};
}
}
if (null != sFormat) {
oRes = new AscCommonExcel.Num();
oRes.f = sFormat;
if ((5 <= oNum.id && oNum.id <= 8) || (15 <= oNum.id && oNum.id <= 17) || (37 <= oNum.id && oNum.id <= 44)) {
oRes.id = oNum.id;
}
}
return oRes;
};
this.ReadStylesContent = function (type, length, oStyleObject) {
var res = c_oSerConstants.ReadOk;
var oThis = this;
......
......@@ -5204,7 +5204,7 @@ Woorksheet.prototype._RecalculatedFunctions=function(cell,bad,setCellFormat){
r = r[0];
if ( r && r.getNumFormatStr ) {
var sCurFormat = c.getNumFormatStr();
if ( g_oDefaultFormat.Num.f == sCurFormat ) {
if ( g_oDefaultFormat.Num.getFormat() == sCurFormat ) {
var sNewFormat = r.getNumFormatStr();
if ( sCurFormat != sNewFormat )
c.setNumFormat( sNewFormat );
......@@ -5493,9 +5493,9 @@ Cell.prototype.setValue=function(val,callback, isCopyPaste){
if(!isCopyPaste){
var sNumFormat;
if(null != this.xfs && null != this.xfs.num)
sNumFormat = this.xfs.num.f;
sNumFormat = this.xfs.num.getFormat();
else
sNumFormat = g_oDefaultFormat.Num.f;
sNumFormat = g_oDefaultFormat.Num.getFormat();
var numFormat = oNumFormatCache.get(sNumFormat);
bIsTextFormat = numFormat.isTextFormat();
}
......@@ -5675,9 +5675,9 @@ Cell.prototype.shiftNumFormat=function(nShift, dDigitsCount){
var bGeneral = true;
var sNumFormat;
if(null != this.xfs && null != this.xfs.num)
sNumFormat = this.xfs.num.f;
sNumFormat = this.xfs.num.getFormat();
else
sNumFormat = g_oDefaultFormat.Num.f;
sNumFormat = g_oDefaultFormat.Num.getFormat();
if("General" != sNumFormat)
{
var oCurNumFormat = oNumFormatCache.get(sNumFormat);
......@@ -5929,8 +5929,8 @@ Cell.prototype.getValue2=function(dDigitsCount, fIsFitMeasurer){
};
Cell.prototype.getNumFormatStr=function(){
if(null != this.xfs && null != this.xfs.num)
return this.xfs.num.f;
return g_oDefaultFormat.Num.f;
return this.xfs.num.getFormat();
return g_oDefaultFormat.Num.getFormat();
};
Cell.prototype.getNumFormat=function(){
return oNumFormatCache.get(this.getNumFormatStr());
......@@ -7160,19 +7160,19 @@ Range.prototype.getNumFormatStr=function(){
{
var xfs = cell.getCompiledStyle();
if(null != xfs && null != xfs.num)
return xfs.num.f;
return xfs.num.getFormat();
}
else
{
//стили столбов и колонок
var row = this.worksheet._getRowNoEmpty(nRow);
if(null != row && null != row.xfs && null != row.xfs.num)
return row.xfs.num.f;
return row.xfs.num.getFormat();
var col = this.worksheet._getColNoEmptyWithAll(nCol);
if(null != col && null != col.xfs && null != col.xfs.num)
return col.xfs.num.f;
return col.xfs.num.getFormat();
}
return g_oDefaultFormat.Num.f;
return g_oDefaultFormat.Num.getFormat();
};
Range.prototype.getNumFormatType=function(){
return this.getNumFormat().getType();
......@@ -9156,8 +9156,8 @@ function _promoteFromTo(from, wsFrom, to, wsTo, bIsPromote, oCanPromote, bCtrl,
}
}
}
if(null != oCell.xfs && null != oCell.xfs.num && null != oCell.xfs.num.f){
var numFormat = oNumFormatCache.get(oCell.xfs.num.f);
if(null != oCell.xfs && null != oCell.xfs.num && null != oCell.xfs.num.getFormat()){
var numFormat = oNumFormatCache.get(oCell.xfs.num.getFormat());
if(numFormat.isDateTimeFormat())
bDate = true;
}
......
This diff is collapsed.
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