【セル型】セルのTD 要素に独自に属性を追加したい
対象製品
SPREAD for ASP.NET 7.0J
詳細
メモ
SPREADのセルはHTML TABLEのTD 要素として出力されます。このTD 要素に独自に属性を追加したい場合は、既存のセル型クラスを継承したカスタムセル型クラスを作成することで、属性を追加することができます。
例として、下記サンプルコードでは以下のように属性「MyAttribution」が追加されます。
◎実行例
<td class="FpSpread1s1s2" MyAttribution="MyText" FpCellType="TextCellType" FpEditorID="FpSpread1_ctl06">属性追加</td>
◎サンプルコード(VB)
◎サンプルコード(C#)
- 既存のセル型を継承しカスタムセルを作成する場合、不具合修正や内部仕様の変更により動作が変わる可能性があります。
SPREADのセルはHTML TABLEのTD 要素として出力されます。このTD 要素に独自に属性を追加したい場合は、既存のセル型クラスを継承したカスタムセル型クラスを作成することで、属性を追加することができます。
例として、下記サンプルコードでは以下のように属性「MyAttribution」が追加されます。
◎実行例
<td class="FpSpread1s1s2" MyAttribution="MyText" FpCellType="TextCellType" FpEditorID="FpSpread1_ctl06">属性追加</td>
◎サンプルコード(VB)
-------------------------------
Webフォームクラス
-------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then
Return
End If
Dim mytx As New MyAttributionText
FpSpread1.ActiveSheetView.Cells(1, 1).CellType = mytx
FpSpread1.ActiveSheetView.Cells(1, 1).Value = "属性追加"
End Sub
-------------------------------
MyAttributionTextクラス
-------------------------------
<Serializable()> Public Class MyAttributionText
Inherits FarPoint.Web.Spread.TextCellType
Public Overrides Function PaintCell(ByVal id As String, ByVal parent As System.Web.UI.WebControls.TableCell, ByVal style As FarPoint.Web.Spread.Appearance, ByVal margin As FarPoint.Web.Spread.Inset, ByVal value As Object, ByVal upperLevel As Boolean) As System.Web.UI.Control
Dim wc As Control = TryCast(MyBase.PaintCell(id, parent, style, margin, value, upperLevel), Control)
parent.Attributes.Add("MyAttribution", "MyText")
Return wc
End Function
End Class
Webフォームクラス
-------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then
Return
End If
Dim mytx As New MyAttributionText
FpSpread1.ActiveSheetView.Cells(1, 1).CellType = mytx
FpSpread1.ActiveSheetView.Cells(1, 1).Value = "属性追加"
End Sub
-------------------------------
MyAttributionTextクラス
-------------------------------
<Serializable()> Public Class MyAttributionText
Inherits FarPoint.Web.Spread.TextCellType
Public Overrides Function PaintCell(ByVal id As String, ByVal parent As System.Web.UI.WebControls.TableCell, ByVal style As FarPoint.Web.Spread.Appearance, ByVal margin As FarPoint.Web.Spread.Inset, ByVal value As Object, ByVal upperLevel As Boolean) As System.Web.UI.Control
Dim wc As Control = TryCast(MyBase.PaintCell(id, parent, style, margin, value, upperLevel), Control)
parent.Attributes.Add("MyAttribution", "MyText")
Return wc
End Function
End Class
◎サンプルコード(C#)
-------------------------------
Webフォームクラス
-------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
return
}
MyAttributionText mytx = new MyAttributionText()
FpSpread1.ActiveSheetView.Cells[1, 1].CellType = mytx
FpSpread1.ActiveSheetView.Cells[1, 1].Value = "属性追加"
}
-------------------------------
MyAttributionTextクラス
-------------------------------
[Serializable()]
public class MyAttributionText : FarPoint.Web.Spread.TextCellType
{
public override Control PaintCell(string id, TableCell parent, FarPoint.Web.Spread.Appearance style, FarPoint.Web.Spread.Inset margin, object ovalue, bool upperLevel)
{
Control wc = base.PaintCell(id, parent, style, margin, ovalue, upperLevel) as Control;
parent.Attributes.Add("MyAttribution", "MyText");
return wc;
}
}
Webフォームクラス
-------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
return
}
MyAttributionText mytx = new MyAttributionText()
FpSpread1.ActiveSheetView.Cells[1, 1].CellType = mytx
FpSpread1.ActiveSheetView.Cells[1, 1].Value = "属性追加"
}
-------------------------------
MyAttributionTextクラス
-------------------------------
[Serializable()]
public class MyAttributionText : FarPoint.Web.Spread.TextCellType
{
public override Control PaintCell(string id, TableCell parent, FarPoint.Web.Spread.Appearance style, FarPoint.Web.Spread.Inset margin, object ovalue, bool upperLevel)
{
Control wc = base.PaintCell(id, parent, style, margin, ovalue, upperLevel) as Control;
parent.Attributes.Add("MyAttribution", "MyText");
return wc;
}
}
キーワード
セル型