您好,
解决的思路是实现GeneralCellType, ISerializeSupport
可以参考代码:- public class MyCellType : GeneralCellType, ISerializeSupport
- {
- private string cornerText = null;
- [DefaultValue((string)null)]
- public string CornerText
- {
- get
- {
- return cornerText;
- }
- set
- {
- cornerText = value;
- }
- }
- public override bool Serialize(XmlTextWriter w)
- {
- if (!string.IsNullOrEmpty(this.CornerText))
- Serializer.SerializeString(this.CornerText, "CornerText", w);
- base.Serialize(w);
- return true;
- }
- public override bool Deserialize(XmlNodeReader r)
- {
- bool readNext = true;
- string cornerText = string.Empty;
- if (r.IsEmptyElement)
- return true;
- while (true)
- {
- if (readNext)
- {
- if (!r.Read())
- break;
- }
- else
- readNext = true;
- switch (r.NodeType)
- {
- case XmlNodeType.Element:
- if (r.Name.Equals("CornerText"))
- {
- cornerText = Serializer.DeserializeString(r);
- CornerText = cornerText;
- }
- r.MoveToFirstAttribute();
- readNext = false;
- break;
- default:
- break;
- }
- if (!readNext)
- break;
- }
- base.Deserialize(r);
- return true;
- }
- }
复制代码- private void button1_Click(object sender, EventArgs e)
- {
- MyCellType m = new MyCellType();
- m.CornerText = "a";
- m.DropDownButton = true;
- m.ButtonAlign = ButtonAlign.Left;
- m.FormatString = @"dd\mm\yy";
- fpSpread1.ActiveSheet.Cells[0, 0].CellType = m;
- fpSpread1.ActiveSheet.Cells[0, 0].Value = @"10\01\1908";
- MessageBox.Show(m.CornerText);
- fpSpread1.Save(path + "abc.xml", false);
- }
- private void button2_Click(object sender, EventArgs e)
- {
- fpSpread1.Reset();
- MessageBox.Show(fpSpread1.Open(path + "abc.xml").ToString());
- MyCellType m = new MyCellType();
- m = (MyCellType)fpSpread1.ActiveSheet.Cells[0, 0].CellType;
- MessageBox.Show(m.CornerText);
- }
复制代码 |