【セル型】セルのTD 要素に独自に属性を追加したい

文書番号 : 25718     文書種別 : 使用方法     最終更新日 : 2008/05/22
文書を印刷する
対象製品
SPREAD for .NET 2.5J Web Forms Edition
詳細
SPREADのセルはHTML TABLEのTD 要素として出力されます。このTD 要素に独自に属性を追加したい場合は、既存のセル型クラスを継承したカスタムセル型クラスを作成することで、属性を追加することができます。

  メモメモ
  • 既存クラスの継承は.NETアプリケーション開発における一般的な手法です。継承方法の詳細についてはMSDNライブラリをご参照ください。(既存クラスのカスタマイズ方法については弊社サポートサービス対象外となります)

例として、下記サンプルコードでは以下のように属性「MyAttribution」が追加されます。

◎実行例
<td valign="Top" MyAttribution="MyText" FpCellType="TextCellType" FpEditorID="FpSpread1__ctl6" style="padding-right:3pxpadding-left:3px">属性追加</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
    parent.Attributes.Add("MyAttribution", "MyText")

    Return MyBase.PaintCell(id, parent, style, margin, value, upperLevel)
  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)
  {
    parent.Attributes.Add("MyAttribution", "MyText");
    return base.PaintCell(id, parent, style, margin, ovalue, upperLevel);
  }
}
キーワード
セル型

この文書は、以前は次のFAQ IDで公開されていました : 11172