如何检查字符串是否包含有效的Excel公式或不使用C#

如何检查字符串是否包含有效的Excel公式或不使用C#

问题描述:

将有一个文本框,用户将输入excel公式。



我想检查用户是否输入了有效公式。



例如,

There will be one text box where user will enter excel formula.

I want to check that user has entered valid formula or not.

for example,

1. SUM(C2:C11*D2:D11) => Valid




2. C2:C11 SUM D2:D11   => Invalid

一个非常简单的方法是使用Interop并使用评估 [ ^ ]方法检查评估的返回值是什么。如果它返回错误,则公式无效。
One quite simple way would be to use Interop and using Evaluate[^] method check what is the return value of the evaluate. If it returns an error, then the formula is invalid.