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 }
Создание пользовательского формата данных ячейки
Для создания пользовательского формата данных ячейки создаёте класс, реализующий интерфейс IDataFormatter
:
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; } }
Применяем класс формата:
DataFormatterManager.Instance.DataFormatters.Add(CellDataFormatFlag.Custom, new MyDataFormatter());
Используем этот формат:
cell.DataFormat = CellDataFormatFlag.Custom; cell.Data = 12345.6789;
Результат:
Вернуться к Документации