While working with number values in Webix SpreadSheet, you have two options of setting format for them:
There is User Guide to help your end users apply number formatting in Webix SpreadSheet.
The following default formats for numbers are available:
The default formats can be customized via the dedicated interface:
You can increase/decrease decimal places via the corresponding API method changeDecimals.
To apply the method to one cell, call the method with the following parameters:
// add 3 decimal places for the value of the cell C3
$$("ss1").changeDecimals(3, 3, 3, "Sheet1");
The method also works for a range of cells. Use the parameters below:
// delete 2 decimal places for values of cells in the range C3:E5
$$("ss1").changeDecimals({row:3, column:3}, {row:5, column:5}, -2, "Sheet1");
It is also possible to apply a custom format of displaying a numeric value to a cell or a selected range of cells.
There is a handy interface for setting a custom number format:
A custom format notation presents a string which consists of several code sections, separated by semicolons.
Each code section may include:
If there are both the condition and the color sections, the condition must go first.
For example:
"[>1000][red];[>100][green]0.0;[blue] Small"
For setting a custom number format for a cell value, make use of the setFormat method. It takes three parameters:
$$("ss1").setFormat(2, 2, "[>1000]>0.0;[>100]Check 0,000.0#;[=0]Nope", "Sheet1");
The condition should be enclosed in square brackets and consist of a comparison operator and a value. For example, the following format colors numbers that are less than or equal to 150 in green and numbers that are greater than 150 in orange.
"[<=150][green];[>150][orange]"
You can also apply conditional formats to cells (for example, highlighting a cell depending on its value).
To specify the color for a section of the format, type the name of one of the available colors (green, red, blue, orange, black, violet or magenta) enclosed in square brackets in the section. The color code must be the second item in the section (after the condition).
The decimal and thousands separators are taken from the applied locale. They can be redefined via the related properties of the i18n object as follows:
webix.i18n.decimalDelimiter = "'";
webix.i18n.setLocale();
webix.i18n.groupDelimiter = "'";
webix.i18n.setLocale();
For prices:
webix.i18n.priceSettings = {
groupDelimiter:" ", // a mark that divides numbers with many digits into groups
decimalDelimiter:" "// the decimal delimiter
};
webix.i18n.setLocale();
The negative sign can be used at the beginning or end of a number: -577 or 577-. As an alternative, you can use parentheses around the number: (577).
The negative sign and its position are determined by the locale. They can be redefined using the following i18n object properties:
webix.i18n.minusPosition = "after";
webix.i18n.setLocale();
webix.i18n.minusSign = "-";
webix.i18n.setLocale();
You can redefine the styling of default number formats via the corresponding CSS classes. There are three of them:
For example, the style of the Number format can be set as in:
<style>
.webix_ssheet_format_int{
color: blue;
font-style: italic;
}
</style>
You will see the result in the number format dialog:
You can replace the last part of the class name, {color} with the name of the color which you want to use for formatting (green, red, blue, orange, black, violet or magenta) and apply the same word in the [color] section of the custom format.
For example, the default CSS style for the green color is the following:
<style>
.webix_ssheet_format_green{
color: green !important;
}
</style>
And it is used in the custom format as follows:
"[>100][green]0.0"
The default date format is mm/dd/yyyy.
The default format can be customized via the dedicated interface:
There are many built-in custom formats that user can enter into Format pattern field. For example, if you want to show the month name fully spelled out, you would use code mmmm. Here is a list of the custom date format codes and their result:
To change date color, define color section before the date code:
[violet]yyyy
Text format is used to present numbers as a string.
The default text format looks as follow:
To change text color, define color section before the @ sign:
[red]@
You can choose a currency symbol via the interface. By default, Spreadsheet offers 5 symbols: US dollar, Euro, Yuan, Portuguese real and Russian ruble.
To change this list, you can add an array of the desired marks to the current locale:
webix.i18n.spreadsheet.formats.currencies = [
"{obj} ¥",
"{obj} €",
"{obj} BYN."
];
Related sample: Spreadsheet: Custom Currency
Possible options for a negative sign position are:
They can be redefined via the related properties of priceSettings object:
webix.i18n.priceSettings = {
minusPosition:"before",
minusSign:"-",
};
webix.i18n.setLocale();
Back to top