作成日: 2017/03/29 最終更新日: 2019/06/05
文書種別
使用方法
詳細
コマンドバーに独自にボタンを追加するには、Initイベント内でコマンドバーに追加するボタンのインスタンスを作成します。次にボタンをコマンドバー上に描画するためにPreRenderイベントを使用します。追加したボタンのイベントをクライアン側のスクリプト関数を使って、SPREADのButtonCommandイベントに関連付けます。
◎サンプルコード(VB)
◎サンプルコード(C#)
◎サンプルコード(VB)
Protected MyBtn As Button
Protected Sub FpSpread1_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.Init
MyBtn = New Button
MyBtn.Width = Unit.Pixel(20)
MyBtn.Height = Unit.Pixel(20)
MyBtn.BackColor = Drawing.Color.Red
MyBtn.CommandName = "ping"
Dim sarg As String = "javascript:" + FpSpread1.ClientID + ".CallBack('ping');return false;"
MyBtn.Attributes.Add("onclick", sarg)
End Sub
Protected Sub FpSpread1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.PreRender
'Dim con As Control = FpSpread1.FindControl("Copy") 'SP3以前の実装方法
Dim con As Control = FpSpread1.FindControl(String.Format("{0}_{1}", FpSpread1.ClientID, "Copy")) 'SP4以降の実装方法
Dim tc As TableCell = CType(con.Parent, TableCell)
Dim tr As TableRow = CType(tc.Parent, TableRow)
Dim c As New TableCell
c.Controls.Add(MyBtn)
tr.Cells.Add(c)
End Sub
Protected Sub MyBtn_Command(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles FpSpread1.ButtonCommand
If e.CommandName = "ping" Then
FpSpread1.Sheets(0).Cells(0, 0).Text += "Clicked"
End If
End Sub
Protected Sub FpSpread1_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.Init
MyBtn = New Button
MyBtn.Width = Unit.Pixel(20)
MyBtn.Height = Unit.Pixel(20)
MyBtn.BackColor = Drawing.Color.Red
MyBtn.CommandName = "ping"
Dim sarg As String = "javascript:" + FpSpread1.ClientID + ".CallBack('ping');return false;"
MyBtn.Attributes.Add("onclick", sarg)
End Sub
Protected Sub FpSpread1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles FpSpread1.PreRender
'Dim con As Control = FpSpread1.FindControl("Copy") 'SP3以前の実装方法
Dim con As Control = FpSpread1.FindControl(String.Format("{0}_{1}", FpSpread1.ClientID, "Copy")) 'SP4以降の実装方法
Dim tc As TableCell = CType(con.Parent, TableCell)
Dim tr As TableRow = CType(tc.Parent, TableRow)
Dim c As New TableCell
c.Controls.Add(MyBtn)
tr.Cells.Add(c)
End Sub
Protected Sub MyBtn_Command(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles FpSpread1.ButtonCommand
If e.CommandName = "ping" Then
FpSpread1.Sheets(0).Cells(0, 0).Text += "Clicked"
End If
End Sub
◎サンプルコード(C#)
Button MyBtn;
protected void FpSpread1_Init(object sender, EventArgs e)
{
MyBtn = new Button();
MyBtn.Width = Unit.Pixel(20);
MyBtn.Height = Unit.Pixel(20);
MyBtn.BackColor = System.Drawing.Color.Red;
MyBtn.CommandName = "ping";
string sarg = "javascript:" + FpSpread1.ClientID + ".CallBack('ping');return false;";
MyBtn.Attributes.Add("onclick", sarg);
// SPREADのイベントを登録
FpSpread1.ButtonCommand += new FarPoint.Web.Spread.SpreadCommandEventHandler(FpSpread1_ButtonCommand);
}
protected void FpSpread1_PreRender(object sender, EventArgs e)
{
//Control con = FpSpread1.FindControl("Copy"); //SP3以前の実装方法
Control con = FpSpread1.FindControl(string.Format("{0}_{1}", FpSpread1.ClientID, "Copy")); //SP4以降の実装方法
TableCell tc = ((TableCell)(con.Parent));
TableRow tr = ((TableRow)(tc.Parent));
TableCell c = new TableCell();
c.Controls.Add(MyBtn);
tr.Cells.Add(c);
}
protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
{
if ((e.CommandName == "ping"))
{
FpSpread1.Sheets[0].Cells[0, 0].Text += "Clicked";
}
}
protected void FpSpread1_Init(object sender, EventArgs e)
{
MyBtn = new Button();
MyBtn.Width = Unit.Pixel(20);
MyBtn.Height = Unit.Pixel(20);
MyBtn.BackColor = System.Drawing.Color.Red;
MyBtn.CommandName = "ping";
string sarg = "javascript:" + FpSpread1.ClientID + ".CallBack('ping');return false;";
MyBtn.Attributes.Add("onclick", sarg);
// SPREADのイベントを登録
FpSpread1.ButtonCommand += new FarPoint.Web.Spread.SpreadCommandEventHandler(FpSpread1_ButtonCommand);
}
protected void FpSpread1_PreRender(object sender, EventArgs e)
{
//Control con = FpSpread1.FindControl("Copy"); //SP3以前の実装方法
Control con = FpSpread1.FindControl(string.Format("{0}_{1}", FpSpread1.ClientID, "Copy")); //SP4以降の実装方法
TableCell tc = ((TableCell)(con.Parent));
TableRow tr = ((TableRow)(tc.Parent));
TableCell c = new TableCell();
c.Controls.Add(MyBtn);
tr.Cells.Add(c);
}
protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
{
if ((e.CommandName == "ping"))
{
FpSpread1.Sheets[0].Cells[0, 0].Text += "Clicked";
}
}
旧文書番号
40221