作成日: 2019/06/25 最終更新日: 2019/06/25
文書種別
使用方法
詳細
製品はセルのコピー&ペースト処理にあたり、.NET Frameworkにおけるオブジェクトのシリアライズ、デシリアライズ処理を利用してその動作を実現しています。
このため独自に作成されたカスタムセルについてコピー&ペースト動作を有効とされる場合には既存のセル動作と対応するよう、下記のように当該カスタムセルクラスにデシリアライズ用のコンストラクタが必要です。
◎サンプルコード(VB)
◎サンプルコード(C#)
このため独自に作成されたカスタムセルについてコピー&ペースト動作を有効とされる場合には既存のセル動作と対応するよう、下記のように当該カスタムセルクラスにデシリアライズ用のコンストラクタが必要です。
◎サンプルコード(VB)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FpSpread1.ActiveSheet.Cells(0, 0).CellType = New CustomCellType()
FpSpread1.ActiveSheet.Cells(0, 0).Value = "ABCDEFG"
End Sub
' 編集用コントロールに標準のテキストボックスを利用する
' 独自のカスタムセルクラス
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
'【追加】:テスト用属性の設定
Public Overrides Sub PaintCell(g As Graphics, r As Rectangle, appearance As FarPoint.Win.Spread.Appearance, value As Object, isSelected As Boolean, isLocked As Boolean, zoomFactor As Single)
appearance.ForeColor = Color.Red
MyBase.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor)
End Sub
End Class
FpSpread1.ActiveSheet.Cells(0, 0).CellType = New CustomCellType()
FpSpread1.ActiveSheet.Cells(0, 0).Value = "ABCDEFG"
End Sub
' 編集用コントロールに標準のテキストボックスを利用する
' 独自のカスタムセルクラス
' 標準のセル型を継承します
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
'【追加】:テスト用属性の設定
Public Overrides Sub PaintCell(g As Graphics, r As Rectangle, appearance As FarPoint.Win.Spread.Appearance, value As Object, isSelected As Boolean, isLocked As Boolean, zoomFactor As Single)
appearance.ForeColor = Color.Red
MyBase.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor)
End Sub
End Class
◎サンプルコード(C#)
private void Form1_Load(object sender, EventArgs e)
{
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;
}
// テスト用属性の設定
public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
{
appearance.ForeColor = Color.Red;
base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
}
}
{
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;
}
// テスト用属性の設定
public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
{
appearance.ForeColor = Color.Red;
base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
}
}
旧文書番号
84104