PowerTools SPREAD for ASP.NET 8.0J
Parse メソッド (BaseCellType)

解析対象の、シートのセルの文字列
この型に基づいてセル型を派生させるときに、このメソッドをオーバーライドすると、 シートのセルから解析され、データモデルに入力される内容が変化します。
構文
'Declaration
 
Public Overridable Function Parse( _
   ByVal s As String _
) As Object
public virtual object Parse( 
   string s
)

パラメータ

s
解析対象の、シートのセルの文字列

戻り値の型

データモデルにobjectとして設定する解析結果
この例では、BaseCellTypeクラスをサブクラス化し、スプレッドシートの先頭セルのカスタムセル型を作成します。セルをダブルクリックすると、新しいエディタが表示され、エディタ内のRGB値を編集してセルの色を変更できます。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FarPoint.Web.Spread;
using System.Drawing;

public partial class SampleCode_Sample1 : System.Web.UI.Page
{
    
  private void Page_Load(object sender,System.EventArgs e)
  {
    var bcTypecell=new bcType();
    FpSpread1.ActiveSheetView.Cells[0,0].CellType=bcTypecell;
    FpSpread1.ActiveSheetView.Columns[0].Width=130;
    FpSpread1.ActiveSheetView.Rows[0].Height=40;
  }
}

[Serializable()]
class bcType:FarPoint.Web.Spread.BaseCellType
{
  public override string Format(object o)
  {
  return base.Format(o);
  }

  public override Control GetEditorControl(string id,TableCell parent,FarPoint.Web.Spread.Appearance style,FarPoint.Web.Spread.Inset margin,object v,bool ul)
  {
    string val=null,val1="",val2="",val3="";
    if(v!=null)
    {
      val=v.ToString();
      string[]colors=val.ToString().Split(new char[]{','});
      if(colors.Length==3)
      {
        val1=colors[0].Trim();
        val2=colors[1].Trim();
        val3=colors[2].Trim();
      }
    }

    Table table= new Table();
    table.CellPadding=0;
    table.CellSpacing=0;
    table.BorderWidth=0;

    TableRow row=new TableRow();
    table.Rows.Add(row);

    TextBox tb=new TextBox();
    tb.Text=val1;
    tb.Columns=3;
    if(ul)
      tb.Attributes.Add("MyEditorComp","Red");

    if(id!=null)
      tb.ID=id+"c1";

    TableCell cell=new TableCell();
    row.Cells.Add(cell);
    cell.Controls.Add(tb);

    tb=new TextBox();
    tb.Text=val2;
    tb.Columns=3;
    if(ul)
      tb.Attributes.Add("MyEditorComp","Green");

    if(id!=null)
      tb.ID=id+"c2";

    cell=new TableCell();
    row.Cells.Add(cell);
    cell.Controls.Add(tb);

    tb=new TextBox();
    tb.Text=val3;
    tb.Columns=3;

    if(ul)
      tb.Attributes.Add("MyEditorComp","Blue");

    if(id!=null)
      tb.ID=id+"c3";

    cell=new TableCell();
    row.Cells.Add(cell);
    cell.Controls.Add(tb);

    return table;
  }

  public override object GetEditorValue(Control owner,string id)
  {
  return base.GetEditorValue(owner,id);
  }

  public override BaseValidator GetValidator()
  {
    return base.GetValidator();
  }

  public override Control PaintCell(string id,TableCell parent,FarPoint.Web.Spread.Appearance style,FarPoint.Web.Spread.Inset margin,object val,bool ul)
  {
    ApplyStyleTo(parent,style,margin,true);
    System.Web.UI.WebControls.Panel p=new System.Web.UI.WebControls.Panel();
    p.Controls.Add(new LiteralControl("Double-Click"));
    p.BackColor=Color.Red;
    p.BorderStyle=BorderStyle.Solid;
    p.BorderColor=Color.Black;
    return p;
  }

  public override object Parse(string s)
  {
  return base.Parse(s);
  }

  public override string ValidateEditorValue(object val)
  {
    return base.ValidateEditorValue(val);
  }


}
Imports FarPoint.Web.Spread
Partial Class SampleCode_Sample1VB
  Inherits System.Web.UI.Page

  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim cell As New bcType()
    FpSpread1.ActiveSheetView.Cells(0, 0).CellType = cell
    FpSpread1.ActiveSheetView.Columns(0).Width = 130
    FpSpread1.ActiveSheetView.Rows(0).Height = 40
  End Sub
End Class

<Serializable()> Public Class bcType
  Inherits FarPoint.Web.Spread.BaseCellType

  Public Overrides Function Format(ByVal o As Object) As String
    Return MyBase.Format(o)
  End Function

  Public Overrides Function GetEditorValue(ByVal owner As Control, ByVal id As String) As Object
    Return MyBase.GetEditorValue(owner, id)
  End Function

  Public Overrides Function GetValidator() As BaseValidator
    Return MyBase.GetValidator()
  End Function

  Public Overrides Function PaintCell(ByVal id As String, ByVal parent As TableCell, ByVal style As FarPoint.Web.Spread.Appearance, ByVal margin As FarPoint.Web.Spread.Inset, ByVal val As Object, ByVal ul As Boolean) As System.Web.UI.Control
    ApplyStyleTo(parent, style, margin, True)
    Dim p As New System.Web.UI.WebControls.Panel()
    p.Controls.Add(New LiteralControl("Double-Click"))
    p.BackColor = System.Drawing.Color.Red
    p.BorderStyle = BorderStyle.Solid
    p.BorderColor = System.Drawing.Color.Black
    Return p
  End Function

  Public Overrides Function Parse(ByVal s As String) As Object
    Return MyBase.Parse(s)
  End Function

  Public Overrides Function ValidateEditorValue(ByVal val As Object) As String
    Return MyBase.ValidateEditorValue(val)
  End Function

  Public Overrides Function GetEditorControl(ByVal id As String, ByVal tc As TableCell, ByVal style As FarPoint.Web.Spread.Appearance, ByVal margin As FarPoint.Web.Spread.Inset, ByVal v As Object, ByVal ul As Boolean) As System.Web.UI.Control
    Dim val As String = Nothing
    Dim val1 As String = ""
    Dim val2 As String = ""
    Dim val3 As String = ""
    Dim u As New System.Web.UI.WebControls.Unit(0)

    While Not v = Nothing
      val = v.ToString()
      Dim colors() As String = val.ToString().Split((New Char() {","}), 3)
      If colors.Length = 3 Then
        val1 = colors(0).Trim()
        val2 = colors(1).Trim()
        val3 = colors(2).Trim()
      End If
    End While

    Dim table As New Table()
    table.CellPadding = 0
    table.CellSpacing = 0
    table.BorderWidth = u

    Dim row As New TableRow()
    table.Rows.Add(row)

    Dim tb As New TextBox()
    tb.Text = val1
    tb.Columns = 3

    If ul Then
      tb.Attributes.Add("MyEditorComp", "Red")
    End If
    While Not id = Nothing
      tb.ID = id + "c1"
    End While

    Dim cell As New TableCell()
    row.Cells.Add(cell)
    cell.Controls.Add(tb)

    tb = New TextBox()
    tb.Text = val2
    tb.Columns = 3
    If ul Then
      tb.Attributes.Add("MyEditorComp", "Green")
    End If

    While Not id = Nothing
      tb.ID = id + "c2"
    End While

    cell = New TableCell()
    row.Cells.Add(cell)
    cell.Controls.Add(tb)

    tb = New TextBox()
    tb.Text = val3
    tb.Columns = 3
    If ul Then
      tb.Attributes.Add("MyEditorComp", "Blue")
    End If

    While Not id = Nothing
      tb.ID = id + "c3"
    End While

    cell = New TableCell()
    row.Cells.Add(cell)
    cell.Controls.Add(tb)

    Return table

  End Function
End Class
参照

BaseCellType クラス
BaseCellType メンバ
ValidateEditorValue メソッド

 

 


© 2003-2015, GrapeCity inc. All rights reserved.