Commit 916e6793 authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander.Trofimov

при распозновании текста с % или currency добавлена поддержка разделителей тысячных.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@52039 954022d7-b5bf-4e40-9824-e11837661b57
parent e009d582
...@@ -2510,10 +2510,8 @@ var oGeneralEditFormatCache = new GeneralEditFormatCache(); ...@@ -2510,10 +2510,8 @@ var oGeneralEditFormatCache = new GeneralEditFormatCache();
function FormatParser() function FormatParser()
{ {
this.rx_percent = new RegExp("^([+-]?)(\\d+\\.?\\d*|\\.\\d+)%$"); this.rx_thouthand = new RegExp("^ *([+-])? *([$€£¥])? *([+-])? *((\\d+(,\\d{3,})*|\\d*)\\.?\\d*) *(р.|%)? *$");
this.rx_date = new RegExp("^ *(((\\d{1,2}) *[/-])? *(\\d{1,2}|[A-Za-z]{3,9}) *([/-]|[/-] *(\\d{2,4}))?)? *((\\d{1,2}) *: *(\\d{1,2})? *(: *(\\d{1,2})?)? *(AM|PM)?)?$"); //добавлять запятую в качестве разделителя в rx_date надо осторожно, чтобы не было путаницу
this.rx_currency = new RegExp("^([+-]?)([$€£¥])?(\\d+\\.?\\d*|\\.\\d+)(р.)?$");
this.rx_date = new RegExp("[A-Za-z]{2,9}|\\d{1,4}|[\\/\\.\\-:,]| +", "g"); this.rx_date = new RegExp("[A-Za-z]{2,9}|\\d{1,4}|[\\/\\.\\-:,]| +", "g");
this.days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; this.days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
this.daysLeap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; this.daysLeap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
...@@ -2523,44 +2521,65 @@ FormatParser.prototype = ...@@ -2523,44 +2521,65 @@ FormatParser.prototype =
{ {
parse : function(value) parse : function(value)
{ {
//format возращается пока только формально, т.к. еще нет списка поддерживаемых форматов //числа вида "+100", "-100" сюда не приходят поэтому формат типа General возвращать не нужно.
var res = null; var res = null;
var match = value.match(this.rx_percent); var match = value.match(this.rx_thouthand);
if(null != match) if(null != match)
{
var sSing1 = match[1];
var sV1 = match[2];
var dVal = parseFloat(sV1);
if ("-" == sSing1)
dVal = -dVal;
dVal /= 100;
res = {format: "0.00%", value: dVal};
}
else
{ {
match = value.match(this.rx_currency); var sSing1 = match[1];
if(null != match) var sSingCurrency = match[2];
var sSing2 = match[3];
var sVal = match[4];
var sSingRubOrPer = match[7];
var oVal = this._parseThouthand(sVal);
if(oVal && (null == sSing1 || null == sSing2))
{ {
var sSing1 = match[1]; var dVal = oVal.number;
var bRubble = false; if ("-" == sSing1 || "-" == sSing2)
var sSing2 = match[2]; dVal = -dVal;
var sSing3 = match[4]; var sFracFormat = "";
if("р." == sSing3) if(parseInt(dVal) != dVal)
bRubble = true; sFracFormat = ".00";
var sV1 = match[3]; var sFormat = null;
var dVal = parseFloat(sV1); if(null == sSingCurrency && null == sSingRubOrPer)
if ("-" == sSing1) {
dVal = -dVal; if(oVal.thouthand)
if(bRubble) sFormat = "#,##0" + sFracFormat;
res = {format: "#,##0.00р.", value: dVal}; }
else else if(null != sSingCurrency)
res = {format: "\\" + sSing2 + "#,##0.00_);[Red](\\" + sSing2 + "#,##0.00)", value: dVal}; sFormat = "\\" + sSingCurrency + "#,##0" + sFracFormat + "_);[Red](\\" + sSingCurrency + "#,##0" + sFracFormat + ")";
else if(null != sSingRubOrPer)
{
if("%" == sSingRubOrPer)
{
dVal /= 100;
sFormat = "0" + sFracFormat + "%";
}
else
sFormat = "#,##0" + sFracFormat + "р.;[Red]-#,##0" + sFracFormat + "р.";
}
if(null != sFormat)
res = {format: sFormat, value: dVal};
} }
else
res = this.parseDate(value);
} }
if(null == res)
res = this.parseDate(value);
return res; return res;
}, },
_parseThouthand : function(val)
{
var oRes = null;
var bThouthand = false;
if(-1 != val.indexOf(","))
{
val = val.replace(/,/g,'');
bThouthand = true;
}
var dNumber = parseFloat(val);
if(!isNaN(dNumber))
oRes = {number: dNumber, thouthand: bThouthand};
return oRes;
},
_parseDateFromArray : function(match) _parseDateFromArray : function(match)
{ {
var res = null; var res = null;
...@@ -2733,7 +2752,6 @@ FormatParser.prototype = ...@@ -2733,7 +2752,6 @@ FormatParser.prototype =
} }
else else
{ {
res.sDateFormat = "d/m/yyyy";
if(this.bFormatMonthFirst) if(this.bFormatMonthFirst)
{ {
var temp = res.d; var temp = res.d;
...@@ -2743,7 +2761,12 @@ FormatParser.prototype = ...@@ -2743,7 +2761,12 @@ FormatParser.prototype =
} }
} }
if(null == res.sDateFormat) if(null == res.sDateFormat)
res.sDateFormat = "d/m/yyyy"; {
if(this.bFormatMonthFirst)
res.sDateFormat = "m/d/yyyy";
else
res.sDateFormat = "d/m/yyyy";
}
if(null != res.y) if(null != res.y)
{ {
if(res.y < 30) if(res.y < 30)
......
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