MESCIUS SPREAD for ASP.NET 10.0J
Serialize メソッド (Appearance)

オブジェクトの保存先のXmlTextWriterオブジェクト
オブジェクトをXMLに保存します。
構文
'Declaration
 
Public Overridable Function Serialize( _
   ByVal w As XmlTextWriter _
) As Boolean
public virtual bool Serialize( 
   XmlTextWriter w
)

パラメータ

w
オブジェクトの保存先のXmlTextWriterオブジェクト

戻り値の型

成功した場合は True、それ以外の場合は False
解説
このメソッドは、Appearanceオブジェクトのパブリックプロパティとパブリックフィールドをシリアル化します。
この例では、新しいAppearanceオブジェクトを作成し、BackColor、ForeColor、Font、HorizontalAlign、VerticalAlignの各プロパティを設定した後、これらの設定をCellオブジェクトのインスタンスに適用します。2つのボタンのクリックイベントで、オブジェクトの逆シリアル化/シリアル化を切り替えることができます。このコードは、Serializer.SaveObjectとSerializer.LoadObjectと同じ処理を行い、ISerializeSupportを実装する任意のオブジェクトに対して機能します。
FarPoint.Web.Spread.Appearance appr = new FarPoint.Web.Spread.Appearance();
FarPoint.Web.Spread.Cell acell;
appr.BackColor = Color.Red;
appr.ForeColor = Color.White;
appr.Font.Bold = true;
appr.HorizontalAlign = HorizontalAlign.Right;
appr.VerticalAlign = VerticalAlign.Top;
acell = FpSpread1.Cells[0,0];
acell.BackColor = appr.BackColor;
acell.ForeColor = appr.ForeColor;
acell.Font.Bold = appr.Font.Bold;
acell.HorizontalAlign = appr.HorizontalAlign;
acell.VerticalAlign = appr.VerticalAlign;
FpSpread1.ActiveSheetView.SetValue(0, 0, "Appearance Test");
FpSpread1.Columns[0].Width = 150;
FpSpread1.Rows[0].Height = 60;


private void Button1_Click(object sender, System.EventArgs e)
{
    string fileName = "D:\\Temp\\myser.xml";
    System.IO.Stream stream = System.IO.File.Open(fileName, System.IO.FileMode.Create);
    System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(stream,     System.Text.Encoding.UTF8);
    writer.Formatting = System.Xml.Formatting.Indented;
    writer.Indentation = 2;
    writer.WriteStartDocument();
    writer.WriteStartElement("Appearance");
    appr.Serialize(writer);
    writer.WriteEndElement();
    writer.WriteEndDocument();
    writer.Close();  
}

private void Button2_Click(object sender, System.EventArgs e)
{
    bool b;
    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
    System.Xml.XmlNode node; 
    System.Xml.XmlNodeReader r;
    doc.Load("D:\\Temp\\myser.xml");
    node = doc.FirstChild;
    while (!node.Name.Equals("Appearance"))
        node = node.NextSibling;
    r = new System.Xml.XmlNodeReader(node);
    r.Read();
    b = appr.Deserialize(r);
    ListBox1.Items.Add(b.ToString());  
}
Dim appr As New FarPoint.Web.Spread.Appearance()
appr.BackColor = Color.Red
appr.ForeColor = Color.White
appr.Font.Bold = True
appr.HorizontalAlign = HorizontalAlign.Right
appr.VerticalAlign = VerticalAlign.Top
Dim acell As FarPoint.Web.Spread.Cell
acell = FpSpread1.Cells(0, 0)
acell.BackColor = appr.BackColor
acell.ForeColor = appr.ForeColor
acell.Font.Bold = appr.Font.Bold
acell.HorizontalAlign = appr.HorizontalAlign
acell.VerticalAlign = appr.VerticalAlign
FpSpread1.ActiveSheetView.SetValue(0, 0, "Appearance Test")
FpSpread1.Columns(0).Width = 150
FpSpread1.Rows(0).Height = 60

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim fileName As String
    Dim stream As System.IO.Stream
    Dim writer As System.Xml.XmlTextWriter
    fileName = "D:\Temp\myser.xml"
    stream = System.IO.File.Open(fileName, System.IO.FileMode.Create)
    writer = New System.Xml.XmlTextWriter(stream, System.Text.Encoding.UTF8)
    writer.Formatting = System.Xml.Formatting.Indented
    writer.Indentation = 2
    writer.WriteStartDocument()
    writer.WriteStartElement("Appearance")
    appr.Serialize(writer)
    writer.WriteEndElement()
    writer.WriteEndDocument()
    writer.Close()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim b As Boolean
    Dim doc As New System.Xml.XmlDocument()
    Dim node As System.Xml.XmlNode
    Dim r As System.Xml.XmlNodeReader
    doc.Load("D:\Temp\myser.xml")
    node = doc.FirstChild
    While Not (node.Name.Equals("Appearance"))
        node = node.NextSibling
    End While
    r = New System.Xml.XmlNodeReader(node)
    r.Read()
    b = appr.Deserialize(r)
    ListBox1.Items.Add(b)
End Sub
参照

Appearance クラス
Appearance メンバ
Deserialize メソッド

 

 


© MESCIUS inc. All rights reserved.