Custom Data Formatter

It is possible to format cell data by using custom cell data formatter, cell data formatter is defined as the interface below:

public interface IDataFormatter
{
  // Return a formatted string for specified cell
  string FormatCell(ReoGridCell cell);

  // Determines that whether or not to check all unformatted cell
  bool PerformTestFormat(); // Usually need to return true here
}

Create a custom cell data formatter

To create a cell data formatter, create a class that implements from IDataFormatter interface:

class MyDataFormatter : IDataFormatter
{
  public string FormatCell(ReoGridCell cell)
  {
   double val = cell.GetData<double>();
   return val < 0 ? string.Format("[{0}]", (-val).ToString("###,###,##0.00")) : val.ToString("###,###,###.00");
  }

  public bool PerformTestFormat()
  {
    return true;
  }
}

To apply this formatter class:

DataFormatterManager.Instance.DataFormatters.Add(CellDataFormatFlag.Custom, new MyDataFormatter());

To use this formatter:

cell.DataFormat = CellDataFormatFlag.Custom;
cell.Data = 12345.6789;

Result:

247


Return to Documentation