如何检查字符串是否包含有效的Excel公式或不使用C# [英] How to check if a string contains valid Excel formula or not using C#

查看:288
本文介绍了如何检查字符串是否包含有效的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.


这篇关于如何检查字符串是否包含有效的Excel公式或不使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆