Commit aadc52b5 authored by konovalovsergey's avatar konovalovsergey

asc_getFormatCells implementation

parent bdc4855b
......@@ -254,15 +254,122 @@ var editor;
}
return res;
};
spreadsheet_api.prototype.asc_getFormatCells = function (info) {
spreadsheet_api.prototype.asc_getFormatCells = function(info) {
var res = [];
if (info) {
var format;
var i;
var cultureInfo = AscCommon.g_aCultureInfos[info.symbol];
var currency = !!cultureInfo;
if (Asc.c_oAscNumFormatType.General === info.type) {
res.push(AscCommon.g_cGeneralFormat);
} else if (Asc.c_oAscNumFormatType.Number === info.type) {
var numberFormat = AscCommon.getNumberFormatSimple(info.separator, info.decimalPlaces);
res.push(numberFormat);
res.push(numberFormat + ';[Red]' + numberFormat);
res.push(AscCommon.getNumberFormat(cultureInfo, info.separator, info.decimalPlaces, false));
res.push(AscCommon.getNumberFormat(cultureInfo, info.separator, info.decimalPlaces, true));
} else if (Asc.c_oAscNumFormatType.Currency === info.type) {
res.push(AscCommon.getCurrencyFormatSimple2(cultureInfo, info.decimalPlaces, currency, false));
res.push(AscCommon.getCurrencyFormatSimple2(cultureInfo, info.decimalPlaces, currency, true));
res.push(AscCommon.getCurrencyFormatSimple(cultureInfo, info.decimalPlaces, currency, currency, false));
res.push(AscCommon.getCurrencyFormatSimple(cultureInfo, info.decimalPlaces, currency, currency, true));
} else if (Asc.c_oAscNumFormatType.Accounting === info.type) {
res.push(AscCommon.getCurrencyFormat(cultureInfo, info.decimalPlaces, currency, currency));
} else if (Asc.c_oAscNumFormatType.Date === info.type) {
//todo locale dependence
if (info.symbol == AscCommon.g_oDefaultCultureInfo.LCID) {
res.push(AscCommon.getShortDateFormat(cultureInfo));
res.push('[$-F800]dddd, mmmm dd, yyyy');
}
res.push(AscCommon.getShortDateFormat2(1, 1, 0, cultureInfo) + ';@');
res.push(AscCommon.getShortDateFormat2(1, 1, 2, cultureInfo) + ';@');
res.push(AscCommon.getShortDateFormat2(2, 2, 2, cultureInfo) + ';@');
res.push(AscCommon.getShortDateFormat2(1, 1, 4, cultureInfo) + ';@');
res.push(AscCommon.getShortDateFormat2(1, 1, 2, cultureInfo) + ' h:mm;@');
res.push('[$-409]' + AscCommon.getShortDateFormat2(1, 1, 2, cultureInfo) + ' h:mm AM/PM;@');
var locale = AscCommon.getLocaleFormat(cultureInfo, false);
res.push(locale + 'mmmmm;@');
res.push(locale + 'mmmm d, yyyy;@');
var separators = ['-', '/', ' '];
for (i = 0; i < separators.length; ++i) {
var separator = separators[i];
res.push(locale + 'd' + separator + 'mmm;@');
res.push(locale + 'd' + separator + 'mmm' + separator + 'yy;@');
res.push(locale + 'dd' + separator + 'mmm' + separator + 'yy;@');
res.push(locale + 'mmm' + separator + 'yy;@');
res.push(locale + 'mmmm' + separator + 'yy;@');
res.push(locale + 'mmmmm' + separator + 'yy;@');
res.push(locale + 'd' + separator + 'mmm' + separator + 'yyyy;@');
}
} else if (Asc.c_oAscNumFormatType.Time === info.type) {
res.push('[$-F400]h:mm:ss AM/PM', 'h:mm;@', 'h:mm AM/PM;@', 'h:mm:ss;@', 'h:mm:ss AM/PM;@', 'mm:ss.0;@',
'[h]:mm:ss;@');
} else if (Asc.c_oAscNumFormatType.Percent === info.type) {
format = '0';
if (info.decimalPlaces > 0) {
format += '.' + '0'.repeat(info.decimalPlaces);
}
format += '%';
res.push(format);
} else if (Asc.c_oAscNumFormatType.Fraction === info.type) {
res.push('# ?/?', '# ??/??', '# ???/???', '# ?/2', '# ?/4', '# ?/8', '# ??/16', '# ?/10', '# ??/100');
} else if (Asc.c_oAscNumFormatType.Scientific === info.type) {
format = '0.' + '0'.repeat(info.decimalPlaces) + 'E+00';
res.push(format);
} else if (Asc.c_oAscNumFormatType.Text === info.type) {
res.push('@');
} else if (Asc.c_oAscNumFormatType.Custom === info.type) {
for (i = 0; i <= 4; ++i) {
res.push(AscCommonExcel.aStandartNumFormats[i]);
}
res.push(AscCommon.getCurrencyFormatSimple(null, 0, false, false, false));
res.push(AscCommon.getCurrencyFormatSimple(null, 0, false, false, true));
res.push(AscCommon.getCurrencyFormatSimple(null, 2, false, false, false));
res.push(AscCommon.getCurrencyFormatSimple(null, 2, false, false, true));
res.push(AscCommon.getCurrencyFormatSimple(null, 0, true, false, false));
res.push(AscCommon.getCurrencyFormatSimple(null, 0, true, false, true));
res.push(AscCommon.getCurrencyFormatSimple(null, 2, true, false, false));
res.push(AscCommon.getCurrencyFormatSimple(null, 2, true, false, true));
for (i = 9; i <= 13; ++i) {
res.push(AscCommonExcel.aStandartNumFormats[i]);
}
res.push(AscCommon.getShortDateFormat(null));
res.push(AscCommon.getShortDateMonthFormat(true, true, null));
res.push(AscCommon.getShortDateMonthFormat(true, false, null));
res.push(AscCommon.getShortDateMonthFormat(false, true, null));
for (i = 18; i <= 21; ++i) {
res.push(AscCommonExcel.aStandartNumFormats[i]);
}
res.push(AscCommon.getShortDateFormat(null) + " h:mm");
for (i = 45; i <= 49; ++i) {
res.push(AscCommonExcel.aStandartNumFormats[i]);
}
//todo add all used in workbook formats
} else {
res.push(AscCommon.g_cGeneralFormat);
}
} else {
res.push(AscCommon.g_cGeneralFormat);
res.push('0.00');
res.push(AscCommon.getCurrencyFormatSimple2(null, 2, true, false));
res.push(AscCommon.getCurrencyFormat(null, 2, true, true));
res.push(AscCommon.getShortDateFormat());
//todo F800 F400
res.push('[$-F800]dddd, mmmm dd, yyyy');
res.push('[$-F400]h:mm:ss AM/PM');
res.push('0.00%');
res.push('# ?/?');
res.push('@');
}
return res;
};
spreadsheet_api.prototype.asc_getLocaleCurrency = function(val) {
var cultureInfo = AscCommon.g_aCultureInfos[val];
if (!cultureInfo) {
cultureInfo = AscCommon.g_aCultureInfos[1033];
}
return AscCommonExcel.getCurrencyFormat(cultureInfo, true, true, true);
return AscCommonExcel.getCurrencyFormat(cultureInfo, 2, true, true);
};
spreadsheet_api.prototype.asc_setLocale = function(val) {
if (!this.isLoadFullApi) {
......
......@@ -1198,41 +1198,37 @@ Num.prototype =
var res = this.f;
if (null != this.id) {
if (15 <= this.id && this.id <= 17) {
var separator;
if ('/' == AscCommon.g_oDefaultCultureInfo.DateSeparator) {
separator = '-';
} else {
separator = '/';
}
switch (this.id) {
case 15:
res = AscCommon.getShortDateMonthFormat(true, true, separator, null);
res = AscCommon.getShortDateMonthFormat(true, true, null);
break;
case 16:
res = AscCommon.getShortDateMonthFormat(true, false, separator, null);
res = AscCommon.getShortDateMonthFormat(true, false, null);
break;
case 17:
res = AscCommon.getShortDateMonthFormat(false, true, separator, null);
res = AscCommon.getShortDateMonthFormat(false, true, null);
break;
}
} else {
switch (this.id) {
case 5:
res = AscCommonExcel.getCurrencyFormatSimple(null, false, true, false);
res = AscCommon.getCurrencyFormatSimple(null, 0, true, false, false);
break;
case 6:
res = AscCommonExcel.getCurrencyFormatSimple(null, false, true, true);
res = AscCommon.getCurrencyFormatSimple(null, 0, true, false, true);
break;
case 7:
res = AscCommonExcel.getCurrencyFormatSimple(null, true, true, false);
res = AscCommon.getCurrencyFormatSimple(null, 2, true, false, false);
break;
case 8:
res = AscCommonExcel.getCurrencyFormatSimple(null, true, true, true);
res = AscCommon.getCurrencyFormatSimple(null, 2, true, false, true);
break;
case 14:
res = AscCommon.getShortDateFormat(null);
break;
case 22:
res = AscCommon.getShortDateFormat(null) + " h:mm";
break;
case 14:
case 27:
case 28:
case 29:
......@@ -1242,28 +1238,28 @@ Num.prototype =
res = AscCommon.getShortDateFormat(null);
break;
case 37:
res = AscCommonExcel.getCurrencyFormatSimple(null, false, false, false);
res = AscCommon.getCurrencyFormatSimple(null, 0, false, false, false);
break;
case 38:
res = AscCommonExcel.getCurrencyFormatSimple(null, false, false, true);
res = AscCommon.getCurrencyFormatSimple(null, 0, false, false, true);
break;
case 39:
res = AscCommonExcel.getCurrencyFormatSimple(null, true, false, false);
res = AscCommon.getCurrencyFormatSimple(null, 2, false, false, false);
break;
case 40:
res = AscCommonExcel.getCurrencyFormatSimple(null, true, false, true);
res = AscCommon.getCurrencyFormatSimple(null, 2, false, false, true);
break;
case 41:
res = AscCommonExcel.getCurrencyFormat(null, false, false, false);
res = AscCommon.getCurrencyFormat(null, 0, false, false);
break;
case 42:
res = AscCommonExcel.getCurrencyFormat(null, false, true, false);
res = AscCommon.getCurrencyFormat(null, 0, true, false);
break;
case 43:
res = AscCommonExcel.getCurrencyFormat(null, true, false, false);
res = AscCommon.getCurrencyFormat(null, 2, false, false);
break;
case 44:
res = AscCommonExcel.getCurrencyFormat(null, true, true, false);
res = AscCommon.getCurrencyFormat(null, 2, true, false);
break;
}
}
......@@ -7652,222 +7648,6 @@ AutoFilterDateElem.prototype.convertDateGroupItemToRange = function(oDateGroupIt
this.dateTimeGrouping = oDateGroupItem.DateTimeGrouping;
};
function getCurrencyFormatSimple(opt_cultureInfo, opt_fraction, opt_currency, opt_red) {
var cultureInfo = opt_cultureInfo ? opt_cultureInfo : AscCommon.g_oDefaultCultureInfo;
var numberFormat = opt_fraction ? '#,##0.00' : '#,##0';
var signCurrencyFormat;
var signCurrencyFormatEnd;
if (opt_currency) {
signCurrencyFormat = signCurrencyFormatEnd = '"' + cultureInfo.CurrencySymbol + '"';
} else {
signCurrencyFormatEnd = signCurrencyFormat = '';
for (var i = 0; i < cultureInfo.CurrencySymbol.length; ++i) {
signCurrencyFormatEnd += '_' + cultureInfo.CurrencySymbol[i];
}
}
var red = opt_red ? '[Red]' : '';
var prefixs = ['_ ', '_-', '_(', '_)'];
var postfix = '';
var positiveFormat;
var negativeFormat;
switch (cultureInfo.CurrencyNegativePattern) {
case 0:
postfix = prefixs[3];
negativeFormat = '\\(' + signCurrencyFormat + numberFormat + '\\)';
break;
case 1:
negativeFormat = '\\-' + signCurrencyFormat + numberFormat;
break;
case 2:
negativeFormat = signCurrencyFormat + '\\ \\-' + numberFormat;
break;
case 3:
postfix = prefixs[1];
negativeFormat = signCurrencyFormat + '\\ ' + numberFormat + '\\-';
break;
case 4:
postfix = prefixs[3];
negativeFormat = '\\(' + numberFormat + signCurrencyFormatEnd + '\\)';
break;
case 5:
negativeFormat = '\\-' + numberFormat + signCurrencyFormatEnd;
break;
case 6:
negativeFormat = numberFormat + '\\-' + signCurrencyFormatEnd;
break;
case 7:
postfix = prefixs[1];
negativeFormat = numberFormat + signCurrencyFormatEnd + '\\-';
break;
case 8:
negativeFormat = '\\-' + numberFormat + '\\ ' + signCurrencyFormatEnd;
break;
case 9:
negativeFormat = '\\-' + signCurrencyFormat + '\\ ' + numberFormat;
break;
case 10:
postfix = prefixs[1];
negativeFormat = numberFormat + '\\ ' + signCurrencyFormatEnd + '\\-';
break;
case 11:
postfix = prefixs[1];
negativeFormat = signCurrencyFormat + '\\ ' + numberFormat + '\\-';
break;
case 12:
negativeFormat = signCurrencyFormat + '\\ \\-' + numberFormat;
break;
case 13:
negativeFormat = numberFormat + '\\-\\ ' + signCurrencyFormatEnd;
break;
case 14:
postfix = prefixs[3];
negativeFormat = '(' + signCurrencyFormat + numberFormat + '\\)';
break;
case 15:
postfix = prefixs[3];
negativeFormat = '\\(' + numberFormat + signCurrencyFormatEnd + '\\)';
break;
}
switch (cultureInfo.CurrencyPositivePattern) {
case 0:
positiveFormat = signCurrencyFormat + numberFormat;
break;
case 1:
positiveFormat = numberFormat + signCurrencyFormatEnd;
break;
case 2:
positiveFormat = signCurrencyFormat + '\\ ' + numberFormat;
break;
case 3:
positiveFormat = numberFormat + '\\ ' + signCurrencyFormatEnd;
break;
}
positiveFormat = positiveFormat + postfix;
return positiveFormat + ';' + red + negativeFormat;
}
function getCurrencyFormat(opt_cultureInfo, opt_fraction, opt_currency, opt_currencyLocale) {
var cultureInfo = opt_cultureInfo ? opt_cultureInfo : AscCommon.g_oDefaultCultureInfo;
var numberFormat;
var nullSignFormat;
if (opt_fraction) {
numberFormat = '#,##0.00';
nullSignFormat = '* "-"??';
} else {
numberFormat = '#,##0';
nullSignFormat = '* "-"';
}
var signCurrencyFormat;
var signCurrencyFormatEnd;
if (opt_currency) {
if (opt_currencyLocale) {
signCurrencyFormat = '[$' + cultureInfo.CurrencySymbol + '-' + cultureInfo.LCID.toString(16).toUpperCase() + ']';
} else {
signCurrencyFormat = '"' + cultureInfo.CurrencySymbol + '"';
}
signCurrencyFormatEnd = signCurrencyFormat;
} else {
signCurrencyFormatEnd = signCurrencyFormat = '';
for (var i = 0; i < cultureInfo.CurrencySymbol.length; ++i) {
signCurrencyFormatEnd += '_' + cultureInfo.CurrencySymbol[i];
}
}
var prefixs = ['_ ', '_-', '_(', '_)'];
var prefix = prefixs[0];
var postfix = prefixs[0];
var positiveNumberFormat = '* ' + numberFormat;
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 + '\\)' + signCurrencyFormatEnd + postfix;
break;
case 5:
prefix = postfix = prefixs[1];
negativeFormat = '\\-* ' + numberFormat + signCurrencyFormatEnd + postfix;
break;
case 6:
negativeFormat = prefix + '* ' + numberFormat + '\\-' + signCurrencyFormatEnd + postfix;
break;
case 7:
negativeFormat = prefix + '* ' + numberFormat + signCurrencyFormatEnd + '\\-';
break;
case 8:
prefix = postfix = prefixs[1];
negativeFormat = '\\-* ' + numberFormat + '\\ ' + signCurrencyFormatEnd + postfix;
break;
case 9:
prefix = postfix = prefixs[1];
negativeFormat = '\\-' + signCurrencyFormat + '\\ * ' + numberFormat + postfix;
break;
case 10:
negativeFormat = prefix + '* ' + numberFormat + '\\ ' + signCurrencyFormatEnd + '\\-';
break;
case 11:
negativeFormat = prefix + signCurrencyFormat + '\\ * ' + numberFormat + '\\-';
break;
case 12:
negativeFormat = prefix + signCurrencyFormat + '\\ * \\-' + numberFormat + postfix;
break;
case 13:
negativeFormat = prefix + '* ' + numberFormat + '\\-\\ ' + signCurrencyFormatEnd + 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 + '\\)\\ ' + signCurrencyFormatEnd + postfix;
break;
}
switch (cultureInfo.CurrencyPositivePattern) {
case 0:
positiveFormat = signCurrencyFormat + positiveNumberFormat;
nullFormat = signCurrencyFormat + nullSignFormat;
break;
case 1:
positiveFormat = positiveNumberFormat + signCurrencyFormatEnd;
nullFormat = nullSignFormat + signCurrencyFormatEnd;
break;
case 2:
positiveFormat = signCurrencyFormat + '\\ ' + positiveNumberFormat;
nullFormat = signCurrencyFormat + '\\ ' + nullSignFormat;
break;
case 3:
positiveFormat = positiveNumberFormat + '\\ ' + signCurrencyFormatEnd;
nullFormat = nullSignFormat + '\\ ' + signCurrencyFormatEnd;
break;
}
positiveFormat = prefix + positiveFormat + postfix;
nullFormat = prefix + nullFormat + postfix;
var textFormat = prefix + '@' + postfix;
return positiveFormat + ';' + negativeFormat + ';' + nullFormat + ';' + textFormat;
}
//----------------------------------------------------------export----------------------------------------------------
var prot;
window['Asc'] = window['Asc'] || {};
......@@ -7973,8 +7753,6 @@ function getCurrencyFormat(opt_cultureInfo, opt_fraction, opt_currency, opt_curr
window['AscCommonExcel'].DateGroupItem = DateGroupItem;
window['AscCommonExcel'].SortCondition = SortCondition;
window['AscCommonExcel'].AutoFilterDateElem = AutoFilterDateElem;
window['AscCommonExcel'].getCurrencyFormatSimple = getCurrencyFormatSimple;
window['AscCommonExcel'].getCurrencyFormat = getCurrencyFormat;
window["Asc"]["CustomFilters"] = window["Asc"].CustomFilters = CustomFilters;
prot = CustomFilters.prototype;
......
......@@ -165,9 +165,11 @@ function FormatObjBracket(sData)
{
var sFirstParam = aParams[0];
var sSecondParam = aParams[1];
if(null != sFirstParam && sFirstParam.length > 0 && null != sSecondParam && sSecondParam.length > 0)
if(null != sFirstParam && sFirstParam.length > 0)
{
this.CurrencyString = sFirstParam;
}
if (null != sSecondParam && sSecondParam.length > 0) {
this.Lid = sSecondParam;
}
}
......@@ -283,6 +285,7 @@ function NumFormat(bAddMinusIfNes)
this.bRepeat = false;
this.Color = -1;
this.ComporationOperator = null;
this.LCID = null;
this.bGeneralChart = false;//если в формате только один текст(например в chart "Основной")
this.bAddMinusIfNes = bAddMinusIfNes;//когда не задано форматирование для отрицательных чисел иногда надо вставлять минус
......@@ -1367,6 +1370,9 @@ NumFormat.prototype =
if (null != item.CurrencyString) {
sText += item.CurrencyString;
}
if (null != item.Lid) {
this.LCID = parseInt(item.Lid, 16);
}
}
else if (numFormat_DecimalPoint == item.type) {
sText += gc_sFormatDecimalPoint;
......@@ -1425,6 +1431,10 @@ NumFormat.prototype =
},
format: function (number, nValType, dDigitsCount, cultureInfo, bChart)
{
if (null != this.LCID) {
//Excel sometimes add 0x10000(0x442 and 0x10442)
cultureInfo = g_aCultureInfos[this.LCID & 0xFFFF];
}
if (null == cultureInfo)
cultureInfo = g_oDefaultCultureInfo;
if(null == nValType)
......@@ -3625,8 +3635,14 @@ function setCurrentCultureInfo(val) {
}
return true;
}
function getShortDateMonthFormat(bDate, bYear, separator, opt_cultureInfo) {
function getShortDateMonthFormat(bDate, bYear, opt_cultureInfo) {
var cultureInfo = opt_cultureInfo ? opt_cultureInfo : AscCommon.g_oDefaultCultureInfo;
var separator;
if ('/' == AscCommon.g_oDefaultCultureInfo.DateSeparator) {
separator = '-';
} else {
separator = '/';
}
var sRes = '';
if (bDate) {
if (-1 != cultureInfo.ShortDatePattern.indexOf('1')) {
......@@ -3670,6 +3686,338 @@ function setCurrentCultureInfo(val) {
}
return dateElems.join('/');
}
function getShortDateFormat2(day, month, year, opt_cultureInfo) {
var cultureInfo = opt_cultureInfo ? opt_cultureInfo : AscCommon.g_oDefaultCultureInfo;
var dateElems = [];
for (var i = 0; i < cultureInfo.ShortDatePattern.length; ++i) {
switch (cultureInfo.ShortDatePattern[i]) {
case '0':
case '1':
if (day > 0) {
dateElems.push('d'.repeat(day));
}
break;
case '2':
case '3':
if (month > 0) {
dateElems.push('m'.repeat(month));
}
break;
case '4':
case '5':
if (year > 0) {
dateElems.push('y'.repeat(month));
}
break;
}
}
return dateElems.join('/');
}
function getNumberFormatSimple(opt_separate, opt_fraction) {
var numberFormat = opt_separate ? '#,##0' : '0';
if (opt_fraction > 0) {
numberFormat += '.' + '0'.repeat(opt_fraction);
}
return numberFormat;
}
function getNumberFormat(opt_cultureInfo, opt_separate, opt_fraction, opt_red) {
var cultureInfo = opt_cultureInfo ? opt_cultureInfo : AscCommon.g_oDefaultCultureInfo;
var numberFormat = getNumberFormatSimple(opt_separate, opt_fraction);
var red = opt_red ? '[Red]' : '';
var positiveFormat;
var negativeFormat;
switch (cultureInfo.CurrencyNegativePattern) {
case 0:
case 4:
case 14:
case 15:
positiveFormat = numberFormat + '_)';
negativeFormat = '\\(' + numberFormat + '\\)';
break;
default:
positiveFormat = numberFormat + '_ ';
negativeFormat = '\\-' + numberFormat + '\\ ';
break;
}
return positiveFormat + ';' + red + negativeFormat;
}
function getLocaleFormat(opt_cultureInfo, opt_currency) {
var cultureInfo = opt_cultureInfo ? opt_cultureInfo : AscCommon.g_oDefaultCultureInfo;
var symbol = opt_currency ? cultureInfo.CurrencySymbol : '';
return '[$' + symbol + '-' + cultureInfo.LCID.toString(16).toUpperCase() + ']';
}
function getCurrencyFormatSimple(opt_cultureInfo, opt_fraction, opt_currency, opt_currencyLocale, opt_red) {
var cultureInfo = opt_cultureInfo ? opt_cultureInfo : AscCommon.g_oDefaultCultureInfo;
var numberFormat = getNumberFormatSimple(true, opt_fraction);
var signCurrencyFormat;
var signCurrencyFormatEnd;
var signCurrencyFormatSpace;
if (opt_currency) {
if (opt_currencyLocale) {
signCurrencyFormat = getLocaleFormat(cultureInfo, true);
} else {
signCurrencyFormat = '"' + cultureInfo.CurrencySymbol + '"';
}
signCurrencyFormatEnd = signCurrencyFormat;
signCurrencyFormatSpace = signCurrencyFormat + '\\ ';
} else {
signCurrencyFormatEnd = signCurrencyFormat = signCurrencyFormatSpace = '';
for (var i = 0; i < cultureInfo.CurrencySymbol.length; ++i) {
signCurrencyFormatEnd += '_' + cultureInfo.CurrencySymbol[i];
}
}
var red = opt_red ? '[Red]' : '';
var prefixs = ['_ ', '_-', '_(', '_)'];
var postfix = '';
var positiveFormat;
var negativeFormat;
switch (cultureInfo.CurrencyNegativePattern) {
case 0:
postfix = prefixs[3];
negativeFormat = '\\(' + signCurrencyFormat + numberFormat + '\\)';
break;
case 1:
negativeFormat = '\\-' + signCurrencyFormat + numberFormat;
break;
case 2:
negativeFormat = signCurrencyFormatSpace + '\\-' + numberFormat;
break;
case 3:
postfix = prefixs[1];
negativeFormat = signCurrencyFormatSpace + numberFormat + '\\-';
break;
case 4:
postfix = prefixs[3];
negativeFormat = '\\(' + numberFormat + signCurrencyFormatEnd + '\\)';
break;
case 5:
negativeFormat = '\\-' + numberFormat + signCurrencyFormatEnd;
break;
case 6:
negativeFormat = numberFormat + '\\-' + signCurrencyFormatEnd;
break;
case 7:
postfix = prefixs[1];
negativeFormat = numberFormat + signCurrencyFormatEnd + '\\-';
break;
case 8:
negativeFormat = '\\-' + numberFormat + '\\ ' + signCurrencyFormatEnd;
break;
case 9:
negativeFormat = '\\-' + signCurrencyFormatSpace + numberFormat;
break;
case 10:
postfix = prefixs[1];
negativeFormat = numberFormat + '\\ ' + signCurrencyFormatEnd + '\\-';
break;
case 11:
postfix = prefixs[1];
negativeFormat = signCurrencyFormatSpace + numberFormat + '\\-';
break;
case 12:
negativeFormat = signCurrencyFormatSpace + '\\-' + numberFormat;
break;
case 13:
negativeFormat = numberFormat + '\\-\\ ' + signCurrencyFormatEnd;
break;
case 14:
postfix = prefixs[3];
negativeFormat = '(' + signCurrencyFormat + numberFormat + '\\)';
break;
case 15:
postfix = prefixs[3];
negativeFormat = '\\(' + numberFormat + signCurrencyFormatEnd + '\\)';
break;
}
switch (cultureInfo.CurrencyPositivePattern) {
case 0:
positiveFormat = signCurrencyFormat + numberFormat;
break;
case 1:
positiveFormat = numberFormat + signCurrencyFormatEnd;
break;
case 2:
positiveFormat = signCurrencyFormatSpace + numberFormat;
break;
case 3:
positiveFormat = numberFormat + '\\ ' + signCurrencyFormatEnd;
break;
}
positiveFormat = positiveFormat + postfix;
return positiveFormat + ';' + red + negativeFormat;
}
function getCurrencyFormatSimple2(opt_cultureInfo, opt_fraction, opt_currency, opt_negative) {
var cultureInfo = opt_cultureInfo ? opt_cultureInfo : AscCommon.g_oDefaultCultureInfo;
var numberFormat = getNumberFormatSimple(true, opt_fraction);
var signCurrencyFormat;
var signCurrencyFormatEnd;
var signCurrencyFormatSpace;
if (opt_currency) {
signCurrencyFormat = signCurrencyFormatEnd = getLocaleFormat(cultureInfo, true);
signCurrencyFormatSpace = signCurrencyFormat + '\\ ';
} else {
signCurrencyFormatEnd = signCurrencyFormat = signCurrencyFormatSpace = '';
for (var i = 0; i < cultureInfo.CurrencySymbol.length; ++i) {
signCurrencyFormatEnd += '_' + cultureInfo.CurrencySymbol[i];
}
}
var positiveFormat;
switch (cultureInfo.CurrencyNegativePattern) {
case 0:
case 1:
case 14:
positiveFormat = signCurrencyFormat + numberFormat;
break;
case 2:
case 3:
case 9:
case 10:
case 11:
case 12:
positiveFormat = signCurrencyFormatSpace + numberFormat;
break;
case 4:
case 5:
case 6:
case 7:
case 15:
positiveFormat = numberFormat + signCurrencyFormatEnd;
break;
case 8:
case 13:
positiveFormat = numberFormat + '\\ ' + signCurrencyFormatEnd;
break;
}
return opt_negative ? positiveFormat + ';[Red]' + positiveFormat : positiveFormat;
}
function getCurrencyFormat(opt_cultureInfo, opt_fraction, opt_currency, opt_currencyLocale) {
var cultureInfo = opt_cultureInfo ? opt_cultureInfo : AscCommon.g_oDefaultCultureInfo;
var numberFormat = getNumberFormatSimple(true, opt_fraction);
var nullSignFormat = '* "-"';
if (opt_fraction) {
nullSignFormat += '?'.repeat(opt_fraction);
}
var signCurrencyFormat;
var signCurrencyFormatEnd;
var signCurrencyFormatSpace;
if (opt_currency) {
if (opt_currencyLocale) {
signCurrencyFormat = getLocaleFormat(cultureInfo, true);
} else {
signCurrencyFormat = '"' + cultureInfo.CurrencySymbol + '"';
}
signCurrencyFormatEnd = signCurrencyFormat;
signCurrencyFormatSpace = signCurrencyFormat + '\\ ';
} else {
signCurrencyFormatEnd = signCurrencyFormat = signCurrencyFormatSpace = '';
for (var i = 0; i < cultureInfo.CurrencySymbol.length; ++i) {
signCurrencyFormatEnd += '_' + cultureInfo.CurrencySymbol[i];
}
}
var prefixs = ['_ ', '_-', '_(', '_)'];
var prefix = prefixs[0];
var postfix = prefixs[0];
var positiveNumberFormat = '* ' + numberFormat;
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 + signCurrencyFormatSpace + '* \\-' + numberFormat + postfix;
break;
case 3:
prefix = postfix = prefixs[1];
negativeFormat = prefix + signCurrencyFormatSpace + '* ' + numberFormat + '\\-';
break;
case 4:
prefix = prefixs[2];
postfix = prefixs[3];
negativeFormat = prefix + '* \\(' + numberFormat + '\\)' + signCurrencyFormatEnd + postfix;
break;
case 5:
prefix = postfix = prefixs[1];
negativeFormat = '\\-* ' + numberFormat + signCurrencyFormatEnd + postfix;
break;
case 6:
negativeFormat = prefix + '* ' + numberFormat + '\\-' + signCurrencyFormatEnd + postfix;
break;
case 7:
negativeFormat = prefix + '* ' + numberFormat + signCurrencyFormatEnd + '\\-';
break;
case 8:
prefix = postfix = prefixs[1];
negativeFormat = '\\-* ' + numberFormat + '\\ ' + signCurrencyFormatEnd + postfix;
break;
case 9:
prefix = postfix = prefixs[1];
negativeFormat = '\\-' + signCurrencyFormatSpace + '* ' + numberFormat + postfix;
break;
case 10:
negativeFormat = prefix + '* ' + numberFormat + '\\ ' + signCurrencyFormatEnd + '\\-';
break;
case 11:
negativeFormat = prefix + signCurrencyFormatSpace + '* ' + numberFormat + '\\-';
break;
case 12:
negativeFormat = prefix + signCurrencyFormatSpace + '* \\-' + numberFormat + postfix;
break;
case 13:
negativeFormat = prefix + '* ' + numberFormat + '\\-\\ ' + signCurrencyFormatEnd + postfix;
break;
case 14:
prefix = prefixs[2];
postfix = prefixs[3];
negativeFormat = prefix + signCurrencyFormatSpace + '* \\(' + numberFormat + '\\)';
break;
case 15:
prefix = prefixs[2];
postfix = prefixs[3];
negativeFormat = prefix + '* \\(' + numberFormat + '\\)\\ ' + signCurrencyFormatEnd + postfix;
break;
}
switch (cultureInfo.CurrencyPositivePattern) {
case 0:
positiveFormat = signCurrencyFormat + positiveNumberFormat;
nullFormat = signCurrencyFormat + nullSignFormat;
break;
case 1:
positiveFormat = positiveNumberFormat + signCurrencyFormatEnd;
nullFormat = nullSignFormat + signCurrencyFormatEnd;
break;
case 2:
positiveFormat = signCurrencyFormatSpace + positiveNumberFormat;
nullFormat = signCurrencyFormatSpace + nullSignFormat;
break;
case 3:
positiveFormat = positiveNumberFormat + '\\ ' + signCurrencyFormatEnd;
nullFormat = nullSignFormat + '\\ ' + signCurrencyFormatEnd;
break;
}
positiveFormat = prefix + positiveFormat + postfix;
nullFormat = prefix + nullFormat + postfix;
var textFormat = prefix + '@' + postfix;
return positiveFormat + ';' + negativeFormat + ';' + nullFormat + ';' + textFormat;
}
var g_aCultureInfos = {
1: {LCID: 1, Name: "ar", CurrencyPositivePattern: 2, CurrencyNegativePattern: 3, CurrencySymbol: "ر.س.‏", NumberDecimalSeparator: ".", NumberGroupSeparator: ",", NumberGroupSizes: [3], DayNames: ["الأحد", "الإثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة", "السبت"], AbbreviatedDayNames: ["الأحد", "الإثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة", "السبت"], MonthNames: ["محرم", "صفر", "ربيع الأول", "ربيع الثاني", "جمادى الأولى", "جمادى الثانية", "رجب", "شعبان", "رمضان", "شوال", "ذو القعدة", "ذو الحجة", ""], AbbreviatedMonthNames: ["محرم", "صفر", "ربيع الأول", "ربيع الثاني", "جمادى الأولى", "جمادى الثانية", "رجب", "شعبان", "رمضان", "شوال", "ذو القعدة", "ذو الحجة", ""], MonthGenitiveNames: [], AbbreviatedMonthGenitiveNames: [], AMDesignator: "ص", PMDesignator: "م", DateSeparator: "/", TimeSeparator: ":", ShortDatePattern: "134"},
2: {LCID: 2, Name: "bg", CurrencyPositivePattern: 3, CurrencyNegativePattern: 8, CurrencySymbol: "лв.", NumberDecimalSeparator: ",", NumberGroupSeparator: " ", NumberGroupSizes: [3], DayNames: ["неделя", "понеделник", "вторник", "сряда", "четвъртък", "петък", "събота"], AbbreviatedDayNames: ["нед", "пон", "вт", "ср", "четв", "пет", "съб"], MonthNames: ["януари", "февруари", "март", "април", "май", "юни", "юли", "август", "септември", "октомври", "ноември", "декември", ""], AbbreviatedMonthNames: ["яну", "фев", "мар", "апр", "май", "юни", "юли", "авг", "сеп", "окт", "ное", "дек", ""], MonthGenitiveNames: [], AbbreviatedMonthGenitiveNames: [], AMDesignator: "", PMDesignator: "", DateSeparator: ".", TimeSeparator: ":", ShortDatePattern: "025"},
......@@ -4111,7 +4459,14 @@ var g_oDefaultCultureInfo = g_aCultureInfos[1033];//en-US//1033//fr-FR//1036//ba
window["AscCommon"].DecodeGeneralFormat = DecodeGeneralFormat;
window["AscCommon"].setCurrentCultureInfo = setCurrentCultureInfo;
window['AscCommon'].getShortDateFormat = getShortDateFormat;
window['AscCommon'].getShortDateFormat2 = getShortDateFormat2;
window['AscCommon'].getShortDateMonthFormat = getShortDateMonthFormat;
window['AscCommon'].getNumberFormatSimple = getNumberFormatSimple;
window['AscCommon'].getNumberFormat = getNumberFormat;
window['AscCommon'].getLocaleFormat = getLocaleFormat;
window['AscCommon'].getCurrencyFormatSimple = getCurrencyFormatSimple;
window['AscCommon'].getCurrencyFormatSimple2 = getCurrencyFormatSimple2;
window['AscCommon'].getCurrencyFormat = getCurrencyFormat;
window["AscCommon"].gc_nMaxDigCount = gc_nMaxDigCount;
window["AscCommon"].gc_nMaxDigCountView = gc_nMaxDigCountView;
......
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