カスタムセルのコピー&ペーストができない

文書番号 : 38845     文書種別 : 使用方法     登録日 : 2015/06/25     最終更新日 : 2015/06/25
文書を印刷する
対象製品
SPREAD for Windows Forms 8.0J
詳細
製品はセルのコピー&ペースト処理にあたり、.NET Frameworkにおけるオブジェクトのシリアライズ、デシリアライズ処理を利用してその動作を実現しています。

このため独自に作成されたカスタムセルについてコピー&ペースト動作を有効とされる場合には既存のセル動作と対応するよう、下記のように当該カスタムセルクラスにデシリアライズ用のコンストラクタが必要です。

◎サンプルコード(VB)
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FpSpread1.ActiveSheet.Cells(0, 0).CellType = New CustomCellType()
        FpSpread1.ActiveSheet.Cells(0, 0).Value = "ABCDEFG"
    End Sub

End Class

' 編集用コントロールに標準のテキストボックスを利用する
' 独自のカスタムセルクラス
<Serializable()> Public Class CustomCellType

    ' 標準のセル型を継承します
    Inherits FarPoint.Win.Spread.CellType.GeneralCellType

    ' 編集用コントロールに標準のテキストボックスを利用します
    Private text As New TextBox()

    ' コンストラクタ
    Public Sub New()
        MyBase.New()
    End Sub

    ' デシリアライズ用コンストラクタ
    ' 本処理が存在しない場合、セル間のコピー&ペースト動作がただしく動作しません
    Public Sub New(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)
        MyBase.New(info, context)
    End Sub

    ' 編集用コントロール取得
    Public Overrides Function GetEditorControl(ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal zoomFactor As Single) As System.Windows.Forms.Control
        Return text
    End Function

    ' 編集用コントロールValue取得
    Public Overrides Function GetEditorValue() As Object
        Return text.Text
    End Function

    ' 編集用コントロールへのValue値設定
    Public Overrides Sub SetEditorValue(ByVal value As Object)
        text.Text = value
    End Sub

End Class


◎サンプルコード(C#)
public partial class Form1 : Form
{
            
    public Form1()
    {
        InitializeComponent();

        CustomCellType testCell = new CustomCellType();
        fpSpread1.ActiveSheet.Cells[0,0].CellType = testCell;
        fpSpread1.ActiveSheet.Cells[0,0].Value = "ABCDEFG";
    }

}

// 標準のセル型を継承した独自のカスタムセルクラス
[Serializable()]
public class CustomCellType : FarPoint.Win.Spread.CellType.GeneralCellType
{
    // 編集用コントロールに標準のテキストボックスを利用します
    TextBox textBox = new TextBox();

    // コンストラクタ
    public CustomCellType() : base()
    {
    }

    // デシリアライズ用コンストラクタ
    // 本処理が存在しない場合、セル間のコピー&ペースト動作がただしく動作しません
    public CustomCellType(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        : base(info, context)
    {
    }

    // 編集用コントロール取得
    public override Control GetEditorControl(FarPoint.Win.Spread.Appearance appearance, float zoomFactor)
    {
        return textBox;
    }

    // 編集用コントロールValue取得
    public override object GetEditorValue()
    {
        return textBox.Text;
    }

    // 編集用コントロールへのValue値設定
    public override void SetEditorValue(object value)
    {
        textBox.Text = (string)value;
    }
}
キーワード
セル型 クリップボード