/// <summary> /// 利用Excel中VBA的Evaluate方法对字符串进行解析计算 /// </summary> /// <param name="str"></param> /// <returns></returns> public static double Cal(this string str) { var app = new Excel.Application(); Excel.Workbook workbook = app.Workbooks.Add(); Excel.Worksheet worksheet = workbook.Worksheets.Add() as Excel.Worksheet; var result = worksheet.Evaluate(str); app.DisplayAlerts = false; app.Quit(); if (double.Parse(result.ToString()) <0) { return 0; } else { return double.Parse(result.ToString()); } }