我正在使用 Microsoft.Office.Interop.Excel
我想将运行公式的结果提取到我的代码中。
我正在做:运行公式,将结果保存在单元格中,将其拉入变量中,清除单元格,将结果返回为:
...
rangeObject = sheetObject.Range["myRange"];
rangeObject.Formula ="myFormula";
string value = rangeObject.Value.ToString();
sheetObject.Range["myRange"].Clear();
return value;
...
rangeObject.Formula ="myFormula";
可以在没有 rangeObject
的情况下运行吗?
有直接的方法吗?
PS:剪贴板可以用吗?
最佳答案
根据the documentation ,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.
关于c# - 您可以在没有 Range 对象的情况下在 C# Interop.Excel 中运行 .Formula 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44202069/