你可以运行没有Range对象的C#Interop.Excel中的Formula?
我正在使用Microsoft.Office.Interop.Excel
我想拉运行公式的结果到我的代码。
我正在做:运行公式,将结果保存在一个单元格,将其拉入variables,清除单元格,返回结果为:
... rangeObject = sheetObject.Range["myRange"]; rangeObject.Formula ="myFormula"; string value = rangeObject.Value.ToString(); sheetObject.Range["myRange"].Clear(); return value; ...
can rangeObject.Formula ="myFormula";
没有rangeObject
运行?
有没有直接的办法?
PS:剪贴板可以使用吗?
根据文档 , Excel.Application
对象的Evaluate
方法(应在Interop中可用)可用于直接评估Microsoft Excel中的公式。
例:
// Cells A1 and B1 of the current worksheet contain 3 and 5, respectively. var myResult = myExcelApp.Evaluate("A1 + B1"); // Yields 8.