可以使用自定义单元格数据格式化器来格式化单元格数据。单元格数据格式化器由以下接口定义:
public interface IDataFormatter
{
// 返回指定单元格的格式化字符串
string FormatCell(ReoGridCell cell);
// 决定是否检查所有未格式化的单元格
bool PerformTestFormat(); // 通常需要返回 true
}
创建自定义单元格数据格式化器
要创建单元格数据格式化器,创建一个实现 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;
