// 示例:strFormULA = (a+b)*c
// 如果替换a=1 b=1 c=2 则结果为 (1+1)*2 = 4 public int CalculateStringFormula(string strFormULA ){ var type = Type.GetTypeFromProgID("MSScriptControl.ScriptControl"); var obj = Activator.CreateInstance(type); type.InvokeMember("Language", System.Reflection.BindingFlags.SetProperty, null, obj, new object[] { "javascript" }); int result = Convert.ToInt32(type.InvokeMember("Eval", System.Reflection.BindingFlags.InvokeMethod, null, obj, new object[] { strFormULA })); return result;}