ReoGrid
DOCUMENT
Data Format

ReoGrid formats cell display and parsing through data formatters (numbers, dates, percent, currency, text, and custom). Add the namespace first:

using unvell.ReoGrid.DataFormat;

Apply a format with SetRangeDataFormat on the worksheet:

var sheet = reoGridControl.CurrentWorksheet;

sheet.SetRangeDataFormat(range, formatFlag, [Optional] object argument = null)

Example:

sheet.SetRangeDataFormat("A1:B2", CellDataFormatFlag.Number,
  new NumberDataFormatter.NumberFormatArgs()
  {
    DecimalPlaces = 4,
    NegativeStyle = NumberDataFormatter.NumberNegativeStyle.RedBrackets,
    UseSeparator = true,
  });

You can also use an action so the change is undoable:

reoGridControl.DoAction(new SetRangeDataFormatAction(range, formatFlag, [Optional] object dataFormatArgs = null));

Quick test:

sheet["B2"] = 12345;
sheet["C2"] = 12345.67890;
sheet["B3"] = -1234;
sheet["C3"] = -1234.56789;

52 (2)

Available Data Format

TypeCellDataFormatFlagArgument
NumberCellDataFormatFlag.NumberNumberDataFormatter.NumberFormatArgs
DateTimeCellDataFormatFlag.DateTimeDateTimeDataFormatter.DateTimeFormatArgs
PercentCellDataFormatFlag.PercentPercentDataFormatter.PercentFormatArgs
CurrencyCellDataFormatFlag.CurrencyCurrencyDataFormatter.CurrencyFormatArgs
TextCellDataFormatFlag.TextNone
Custom ExtensionCellDataFormatFlag.CustomAny object

Number

Number format supports thousands separators, decimal places, and negative styles.

322

Code sample:

sheet.SetRangeDataFormat("A1:E7", CellDataFormatFlag.Number,
  new NumberDataFormatter.NumberFormatArgs()
  {
    DecimalPlaces = 4,
    UseSeparator = true,
  });

Negative number style

Negative styles come from NumberNegativeStyle:

Negative number styleExampleEnum Value
No style-123,456.789Minus
Red123,456.789Red
Red Minus-123,456.789Red |Minus
Bracketed(123,456.789)Brackets
Bracketed Red(123,456.789)Brackets |Red
Bracketed Red Minus(-123,456.789)Brackets |Red |Minus
Japanese Prefix▲ 123,456,789Prefix_Sankaku
Japanese Prefix (ReoGrid Pro)▲ 123,456,789Prefix_Sankaku |Red

Example:

323

var sheet = grid.CurrentWorksheet;

sheet.SetRangeDataFormat("B2", CellDataFormatFlag.Number, 
  new NumberDataFormatter.NumberFormatArgs
  {
    DecimalPlaces = 3,
    NegativeStyle = NumberDataFormatter.NumberNegativeStyle.RedBrackets,
    UseSeparator = true,
  });

sheet["B2"] = -12345.67;

DateTime

Specify culture and pattern:

48 (2)

sheet.SetRangeDataFormat(RangePosition.EntireRange, CellDataFormatFlag.DateTime,
  new DateTimeDataFormatter.DateTimeFormatArgs
  {
    CultureName = "en-US",
    Format = "yyyy/MM/dd",
  });

Percent

Define decimal places; values are shown as percentages:

49 (2)

sheet.SetRangeDataFormat(RangePosition.EntireRange, CellDataFormatFlag.Percent,
  new NumberDataFormatter.NumberFormatArgs
  {
    DecimalPlaces = 2,
  });

Currency

Currency extends number formatting with currency symbols before or after the value.

325

var sheet = grid.CurrentWorksheet;

sheet.SetRangeDataFormat("B2", CellDataFormatFlag.Currency,
  new CurrencyDataFormatter.CurrencyFormatArgs
  {
    CultureEnglishName = "en-US",
    DecimalPlaces = 2,
    UseSeparator = true,
    PrefixSymbol = "$"
  });

sheet["B2"] = 1234;

Add a space before symbol and number

Put a space after the symbol if desired:

324

sheet.SetRangeDataFormat("B2", CellDataFormatFlag.Currency,
  new CurrencyDataFormatter.CurrencyFormatArgs
  {
    CultureEnglishName = "en-US",
    DecimalPlaces = 2,
    UseSeparator = true,
    PrefixSymbol = "$ "
  });

Set a postfix instead:

326

sheet.SetRangeDataFormat("B2", CellDataFormatFlag.Currency,
  new CurrencyDataFormatter.CurrencyFormatArgs
  {
    CultureEnglishName = "en-US",
    DecimalPlaces = 2,
    UseSeparator = true,
    PostfixSymbol = " USD"
  });

Text

Use Text to keep values as literal strings with no formatting.

51 (2)

sheet.SetRangeDataFormat(RangePosition.EntireRange, CellDataFormatFlag.Text, null);

Custom cell data formatter

Implement your own formatter via CellDataFormatFlag.Custom. See Custom Data Format for details.


Was the content of the page helpful?

© 2012-2025UNVELL Inc.