Skip to content

Spreadsheet format codes

Use a spreadsheet code when you need a precise mask rather than the preset options. With the Pro setup, use kind: 'code' instead of kind: 'preset':

grid.columns = [{
prop: 'amount', name: 'Amount',
dataGridFormat: { value: {
kind: 'code', formatCode: '#,##0.00', locale: 'en-US',
} },
}];

The following examples use en-US unless the code carries a locale token:

UseRaw valueformatCodeDisplay
Grouped decimals1234.5#,##0.001,234.50
Optional decimal digits12.50.##12.5
Padded numeric label420000000042
Percent ratio0.1250.0%12.5%
Scientific12000.00E+001.20E+03
Rational fraction1.25# ?/?1 1/4
Fixed denominator1.375# ?/81 3/8
Millions for BI15000000.0,,"M"1.5M
Literal unit120" kg"12 kg
German euro pattern1234.5[$€-407]#,##0.00€1.234,50
Elapsed time in days2.25[h]:mm:ss54:00:00

0 requires a digit; # makes it optional; ? reserves digit space. Trailing commas scale the display by thousands without changing the source. Quoted literals add labels without converting units. Fractions approximate a value for display; they do not store rational arithmetic.

Up to four semicolon-separated sections describe positive, negative, zero and text values:

const value = {
kind: 'code' as const,
formatCode: '0.00;[Red](0.00);"zero";"value: "@',
};

This displays -12.5 as (12.50) in red, 0 as zero, and hello as value: hello. Conditional sections such as [Red][<0]0.0;0.0 choose a pattern by value. Supported code families also include date/time tokens, elapsed [h]/[m]/[s], escaped literals, named/indexed colors, _ spacing and * fill. Locale tokens override the fallback locale.

import { validateDataGridFormatCode } from '@revolist/revogrid-pro';
const diagnostics = validateDataGridFormatCode('#,##0.00');
if (diagnostics.length) console.log(diagnostics);

Malformed codes fall back to raw display. RevoGrid supports common spreadsheet families; do not assume every Excel feature or another BI tool’s mask grammar is identical. Test imported codes against representative positive, negative, zero, blank and text values.

A code is display metadata, not an input mask. Code formats do not enable the numeric-preset save conversion. Use editing validation or a numeric editor. A padded account code or phone number should usually be a source string so leading zeros survive imports and exports. Use the time guide before assigning dates or elapsed values.

For runtime format state and native workbook number formats, see Format Cells and Excel cell formatting. Power BI has its own custom format rules; translate the intent rather than assuming masks are interchangeable.