シートの左上(コーナー)ヘッダに文字列を表示したい
対象製品
SPREAD for .NET 2.5J Web Forms Edition
詳細
SPREADにはシートの左上(コーナー)ヘッダのセルに値を設定することはできませんので、方法としてはカスタムセル型クラスを作成してコーナーのセルに設定することで、文字列を表示させることができます。

  
メモ
◎サンプルコード(VB)
◎サンプルコード(C#)
  

- 既存クラスの継承は.NETアプリケーション開発における一般的な手法です。継承方法の詳細についてはMSDNライブラリをご参照ください。(既存クラスのカスタマイズ方法については弊社サポートサービス対象外となります)
- コーナーのセルの文字列はExcelファイルへのエクスポートの対象になりません。
◎サンプルコード(VB)
-------------------------------
Webフォームクラス
-------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then
Return
End If
FpSpread1.Sheets(0).SheetCornerStyle.CellType = New myCornerText
End Sub
-------------------------------
MyLButtonCell1クラス
-------------------------------
<Serializable()> Public Class myCornerText
Inherits FarPoint.Web.Spread.LabelCellType
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
style.Font.Size = FontUnit.Point(14)
style.ForeColor = Drawing.Color.Red
style.BackColor = Drawing.Color.Blue
Return MyBase.PaintCell(id, parent, style, margin, "Cor", upperLevel)
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
FpSpread1.Sheets(0).SheetCornerStyle.CellType = New myCornerText
End Sub
-------------------------------
MyLButtonCell1クラス
-------------------------------
<Serializable()> Public Class myCornerText
Inherits FarPoint.Web.Spread.LabelCellType
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
style.Font.Size = FontUnit.Point(14)
style.ForeColor = Drawing.Color.Red
style.BackColor = Drawing.Color.Blue
Return MyBase.PaintCell(id, parent, style, margin, "Cor", upperLevel)
End Function
End Class
◎サンプルコード(C#)
-------------------------------
Webフォームクラス
-------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
return;
}
FpSpread1.Sheets[0].SheetCornerStyle.CellType = new myCornerText();
}
-------------------------------
MyButtonCell1クラス
-------------------------------
[Serializable()] public class myCornerText : FarPoint.Web.Spread.LabelCellType
{
public override System.Web.UI.Control PaintCell(string id, System.Web.UI.WebControls.TableCell parent, FarPoint.Web.Spread.Appearance style, FarPoint.Web.Spread.Inset margin, object value, bool upperLevel)
{
style.Font.Size = FontUnit.Point(14);
style.ForeColor = System.Drawing.Color.Red;
style.BackColor = System.Drawing.Color.Blue;
return base.PaintCell(id, parent, style, margin, "Cor", upperLevel);
}
}
Webフォームクラス
-------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
return;
}
FpSpread1.Sheets[0].SheetCornerStyle.CellType = new myCornerText();
}
-------------------------------
MyButtonCell1クラス
-------------------------------
[Serializable()] public class myCornerText : FarPoint.Web.Spread.LabelCellType
{
public override System.Web.UI.Control PaintCell(string id, System.Web.UI.WebControls.TableCell parent, FarPoint.Web.Spread.Appearance style, FarPoint.Web.Spread.Inset margin, object value, bool upperLevel)
{
style.Font.Size = FontUnit.Point(14);
style.ForeColor = System.Drawing.Color.Red;
style.BackColor = System.Drawing.Color.Blue;
return base.PaintCell(id, parent, style, margin, "Cor", upperLevel);
}
}
キーワード
セル型
この文書は、以前は次のFAQ IDで公開されていました : 11140