【セル型】 ハイパーリンクでウィンドウを表示し、そのサイズを制御したい
対象製品
SPREAD for .NET 2.5J Web Forms Edition
詳細
HyperLinkCellTypeクラスを継承するカスタムセル型を作成することで可能です。
メモ
【VB サンプルコード】
【C#サンプルコード】

- 既存クラスの継承は.NETアプリケーション開発における一般的な手法です。継承方法の詳細についてはMSDNライブラリをご参照ください。(既存クラスのカスタマイズ方法については弊社サポートサービス対象外となります)
【VB サンプルコード】
------------------------
Webフォームクラス
------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IsPostBack Then
Return
End If
Dim hc As New MyHyperLinkCell
hc.NavigateUrl = "http://www.grapecity.com/tools/"
FpSpread1.Sheets(0).Cells(0, 0).CellType = hc
''デザイン関連
FpSpread1.Sheets(0).Columns(0).Font.Size = FontUnit.XSmall
FpSpread1.Sheets(0).Columns(0).Width = 200
End Sub
------------------------
カスタムセル型クラス
------------------------
<Serializable()> Public Class MyHyperLinkCell
Inherits FarPoint.Web.Spread.HyperLinkCellType
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 link As WebControl = CType(MyBase.PaintCell(id, parent, style, margin, value, upperLevel), WebControl)
Dim sscript As String = "javascript:window.open('" + Me.NavigateUrl + "','_blank', 'width=500,height = 50') return false"
link.Attributes.Add("onclick", sscript)
Return link
End Function
End Class
Webフォームクラス
------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IsPostBack Then
Return
End If
Dim hc As New MyHyperLinkCell
hc.NavigateUrl = "http://www.grapecity.com/tools/"
FpSpread1.Sheets(0).Cells(0, 0).CellType = hc
''デザイン関連
FpSpread1.Sheets(0).Columns(0).Font.Size = FontUnit.XSmall
FpSpread1.Sheets(0).Columns(0).Width = 200
End Sub
------------------------
カスタムセル型クラス
------------------------
<Serializable()> Public Class MyHyperLinkCell
Inherits FarPoint.Web.Spread.HyperLinkCellType
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 link As WebControl = CType(MyBase.PaintCell(id, parent, style, margin, value, upperLevel), WebControl)
Dim sscript As String = "javascript:window.open('" + Me.NavigateUrl + "','_blank', 'width=500,height = 50') return false"
link.Attributes.Add("onclick", sscript)
Return link
End Function
End Class
【C#サンプルコード】
------------------------
Webフォームクラス
------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
return;
}
MyHyperLinkCell hc = new MyHyperLinkCell();
hc.NavigateUrl = "http://www.grapecity.com/tools/";
FpSpread1.Sheets[0].Cells[0, 0].CellType = hc;
//デザイン関連
FpSpread1.Sheets[0].Columns[0].Font.Size = FontUnit.XSmall;
FpSpread1.Sheets[0].Columns[0].Width = 200;
}
------------------------
カスタムセル型クラス
------------------------
[Serializable()]
public class MyHyperLinkCell : FarPoint.Web.Spread.HyperLinkCellType
{
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)
{
Control c = (Control)base.PaintCell(id, parent, style, margin, value, upperLevel);
HyperLink hl = (HyperLink)c;
string sscript = "javascript:window.open('" + this.NavigateUrl + "','_blank', 'width=500,height = 50') return false";
hl.Attributes.Add("onclick", sscript);
return hl;
}
}
Webフォームクラス
------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
return;
}
MyHyperLinkCell hc = new MyHyperLinkCell();
hc.NavigateUrl = "http://www.grapecity.com/tools/";
FpSpread1.Sheets[0].Cells[0, 0].CellType = hc;
//デザイン関連
FpSpread1.Sheets[0].Columns[0].Font.Size = FontUnit.XSmall;
FpSpread1.Sheets[0].Columns[0].Width = 200;
}
------------------------
カスタムセル型クラス
------------------------
[Serializable()]
public class MyHyperLinkCell : FarPoint.Web.Spread.HyperLinkCellType
{
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)
{
Control c = (Control)base.PaintCell(id, parent, style, margin, value, upperLevel);
HyperLink hl = (HyperLink)c;
string sscript = "javascript:window.open('" + this.NavigateUrl + "','_blank', 'width=500,height = 50') return false";
hl.Attributes.Add("onclick", sscript);
return hl;
}
}
キーワード
クライアント側スクリプト セル型
この文書は、以前は次のFAQ IDで公開されていました : 9142