GrapeCity SPREAD for WPF 2.0J
Formatter プロパティ

セルのフォーマッターを取得または設定します。
構文
'Declaration
 
Public Property Formatter As IFormatter
public IFormatter Formatter {get; set;}

プロパティ値

セルのフォーマッターを指定する IFormatter オブジェクト。既定値は null 参照 (Visual Basicでは Nothing) です。
次のサンプルはGeneralCellTypeを作成し日本の通貨に換算するためにカスタムFormatterを設定します。
public void CreateGeneralCell2()
{
    GeneralCellType generalCellType1 = new GeneralCellType();
    //Set Custom Formatter, convert the numer to Japanese Currency.
    generalCellType1.Formatter = new CustomFormatter();
    this._gcSpreadGrid1[0, 0].CellType = generalCellType1;
}
class CustomFormatter : IFormatter
{
    System.Globalization.NumberFormatInfo info = new System.Globalization.NumberFormatInfo();
    public CustomFormatter()
    {
        info.CurrencySymbol = "円";
    }
    public string Format(object obj)
    {
        if (obj != null)
        {
            decimal value;
            if (decimal.TryParse(obj.ToString(), out value))
            {
                return value.ToString("C2", info);
            }
        }
        return "円0.00";
    }

    public object Parse(string str)
    {
        decimal result;
        decimal.TryParse(str, System.Globalization.NumberStyles.AllowCurrencySymbol, info, out result);
        return result;
    }
}
Public Sub CreateGeneralCell2()
    Dim generalCellType1 As New GeneralCellType()
    'Set Custom Formatter, convert the numer to Japanese Currency.
    generalCellType1.Formatter = New CustomFormatter()
    Me._gcSpreadGrid1(0, 0).CellType = generalCellType1
End Sub
Private Class CustomFormatter
    Implements IFormatter
    Private info As New System.Globalization.NumberFormatInfo()
    Public Sub New()
        info.CurrencySymbol = "円"
    End Sub
    Public Function Format(obj As Object) As String Implements IFormatter.Format
        If obj IsNot Nothing Then
            Dim value As Decimal
            If Decimal.TryParse(obj.ToString(), value) Then
                Return value.ToString("C2", info)
            End If
        End If
        Return "円0.00"
    End Function

    Public Function Parse(str As String) As Object Implements IFormatter.Parse
        Dim result As Decimal
        Decimal.TryParse(str, System.Globalization.NumberStyles.AllowCurrencySymbol, info, result)
        Return result
    End Function
End Class
参照

GeneralCellType クラス
GeneralCellType メンバ

 

 


Copyright © 2012 GrapeCity inc. All rights reserved.