回复 3楼taxsoft的帖子
taxsoft 你好,
请问是否在 自定义公式 类前添加 "[Serializable]”?下面是我的测试代码,成功保存了自定义公式:
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- CubeFunctionInfo fun = new CubeFunctionInfo();
- this.fpSpread1.Sheets[0].AddCustomFunction(fun);
- this.fpSpread1.Sheets[0].SetFormula(2, 0, "CUBE(5)");
- }
- private void saveXMLToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.fpSpread1.Save(System.IO.Path.Combine(Application.StartupPath, "test.xml"), false);
- }
- private void openXMLToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.fpSpread1.Open(System.IO.Path.Combine(Application.StartupPath, "test.xml"));
- }
- }
- [Serializable]
- public class CubeFunctionInfo : FunctionInfo
- {
- public override string Name { get { return "CUBE"; } }
- public override int MinArgs { get { return 1; } }
- public override int MaxArgs { get { return 1; } }
- public override object Evaluate(object[] args)
- {
- double num = CalcConvert.ToDouble(args[0]);
- return num * num * num;
- }
- }
复制代码 |