简体   繁体   English

如何直接在 POI Apache/NPOI 中评估公式/参数的字符串表示形式

[英]How to evaluate a string representation of a formula/parameter in POI Apache/NPOI directly

I want to convert some spreadsheets which contain references to a plugin-defined function which we are trying to remove.我想转换一些包含对我们试图删除的插件定义的 function 的引用的电子表格。 There is a method to convert this which works in VBA by using SUMIFS and generating a table有一种方法可以通过使用 SUMIFS 并生成表格在 VBA 中进行转换

I am at the step where I have parsed the formulas and extracted the parameters used for the function (done by bracket counting).我正在解析公式并提取用于 function 的参数(通过括号计数完成)的步骤。 I have hit a snag.我遇到了一个障碍。 How do I get NPOI/POI Apache to evaluate the things.我如何获得 NPOI/POI Apache 来评估这些东西。 It seems to demand everything be done inside a cell.它似乎要求一切都在一个牢房内完成。 This isn't possible in this scenario (since these are parameters not cell formulas, so they don't have a cell in which to evaluate them).在这种情况下这是不可能的(因为这些是参数而不是单元格公式,因此它们没有用于评估它们的单元格)。

There is the OperandResolver class which seems to be along the right lines, but it wants a ValueEval type as its input which I can't figure out at all.有 OperandResolver class 似乎是正确的,但它想要一个 ValueEval 类型作为它的输入,我根本无法弄清楚。 Currently I can only get the parameters as strings.目前我只能将参数作为字符串获取。 Like "A1", "0.9", "SomeOtherFunction(...)" etc. Those are what I have.像“A1”、“0.9”、“SomeOtherFunction(...)”等。这些就是我所拥有的。

Basically I need something like基本上我需要类似的东西

pseudocode:    
var result = Evaluate_Formula_String(string formula, var Contextual_Information_eg_current_Worksheet)

Where the result would contain either a string or something easily converted into a string.结果将包含字符串或易于转换为字符串的内容。

The function you need seems to be simply Application.Evaluate.您需要的 function 似乎只是 Application.Evaluate。 It takes a string and evaluates it.它接受一个字符串并对其进行评估。

Reference page: https://docs.microsoft.com/en-us/office/vba/api/excel.application.evaluate参考页: https://docs.microsoft.com/en-us/office/vba/api/excel.application.evaluate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM