Commit 74ae3ea8 authored by Alexander Trofimov's avatar Alexander Trofimov Committed by GitHub

Merge pull request #97 from ONLYOFFICE/feature/format-cells

Feature/format cells
parents 20f00f63 bbbaf640
......@@ -217,31 +217,145 @@ var editor;
this.asc_SendThemeColors(_ret_array, standart_colors);
};
spreadsheet_api.prototype.asc_getLocaleExample = function(val, number, date) {
var res = '';
var cultureInfo = AscCommon.g_aCultureInfos[val];
if (cultureInfo) {
var numFormatDigit = AscCommon.oNumFormatCache.get('#,##0.00');
var formatDate = AscCommon.getShortDateFormat(cultureInfo);
formatDate += " h:mm";
if (cultureInfo.AMDesignator && cultureInfo.PMDesignator) {
formatDate += " AM/PM";
}
var numFormatDate = AscCommon.oNumFormatCache.get(formatDate);
res += numFormatDigit.formatToChart(number, cultureInfo);
res += '; ';
res += numFormatDate.formatToChart(date.getExcelDateWithTime(), cultureInfo);
}
return res;
};
spreadsheet_api.prototype.asc_getCurrencySymbols = function () {
var result = {};
for (var key in AscCommon.g_aCultureInfos) {
result[key] = AscCommon.g_aCultureInfos[key].CurrencySymbol;
}
return result;
};
spreadsheet_api.prototype.asc_getLocaleExample = function(format, value, culture) {
var cultureInfo = AscCommon.g_aCultureInfos[culture] || AscCommon.g_oDefaultCultureInfo;
var numFormat = AscCommon.oNumFormatCache.get(format);
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) {
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);
res.push('0.00');
res.push('0.00E+00');
res.push(AscCommon.getCurrencyFormat(cultureInfo, 2, currency, true));
res.push(AscCommon.getCurrencyFormatSimple2(cultureInfo, 2, currency, false));
res.push(AscCommon.getShortDateFormat(cultureInfo));
//todo F400
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) {
......@@ -3245,7 +3359,9 @@ var editor;
prot["asc_GetFontThumbnailsPath"] = prot.asc_GetFontThumbnailsPath;
prot["asc_setDocInfo"] = prot.asc_setDocInfo;
prot["asc_getLocaleExample"] = prot.asc_getLocaleExample;
prot['asc_getCurrencySymbols'] = prot.asc_getCurrencySymbols;
prot['asc_getLocaleExample'] = prot.asc_getLocaleExample;
prot['asc_getFormatCells'] = prot.asc_getFormatCells;
prot["asc_getLocaleCurrency"] = prot.asc_getLocaleCurrency;
prot["asc_setLocale"] = prot.asc_setLocale;
prot["asc_getEditorPermissions"] = prot.asc_getEditorPermissions;
......
......@@ -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();
......@@ -5129,7 +5133,7 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){
};
Cell.prototype.getValueData = function(){
this._checkDirty();
var formula = this.formulaParsed ? this.formulaParsed.Formula : null;;
var formula = this.formulaParsed ? this.formulaParsed.Formula : null;
return new UndoRedoData_CellValueData(formula, this.oValue.clone());
};
Cell.prototype.setValueData = function(Val){
......
This diff is collapsed.
......@@ -2132,6 +2132,18 @@
};
var g_oCacheMeasureEmpty = new CCacheMeasureEmpty();
/** @constructor */
function asc_CFormatCellsInfo() {
this.type = Asc.c_oAscNumFormatType.General;
this.decimalPlaces = 2;
this.separator = false;
this.symbol = null;
}
asc_CFormatCellsInfo.prototype.asc_setType = function (val) {this.type = val;};
asc_CFormatCellsInfo.prototype.asc_setDecimalPlaces = function (val) {this.decimalPlaces = val;};
asc_CFormatCellsInfo.prototype.asc_setSeparator = function (val) {this.separator = val;};
asc_CFormatCellsInfo.prototype.asc_setSymbol = function (val) {this.symbol = val;};
/*
* Export
* -----------------------------------------------------------------------------
......@@ -2301,4 +2313,11 @@
prot["asc_getType"] = prot.asc_getType;
window["AscCommonExcel"].g_oCacheMeasureEmpty = g_oCacheMeasureEmpty;
window["Asc"].asc_CFormatCellsInfo = asc_CFormatCellsInfo;
prot = asc_CCompleteMenu.prototype;
prot["asc_setType"] = prot.asc_setType;
prot["asc_setDecimalPlaces"] = prot.asc_setDecimalPlaces;
prot["asc_setSeparator"] = prot.asc_setSeparator;
prot["asc_setSymbol"] = prot.asc_setSymbol;
})(window);
This diff is collapsed.
......@@ -229,6 +229,7 @@
//NumFormat defines
var c_oAscNumFormatType = {
None : -1,
General : 0,
Custom : 1,
Text : 2,
......@@ -1200,6 +1201,7 @@
prot['BlockInteraction'] = prot.BlockInteraction;
window['Asc']['c_oAscNumFormatType'] = window['Asc'].c_oAscNumFormatType = c_oAscNumFormatType;
prot = c_oAscNumFormatType;
prot['None'] = prot.None;
prot['General'] = prot.General;
prot['Custom'] = prot.Custom;
prot['Text'] = prot.Text;
......
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