如何知道,如果一个单元具有在C#公式中的错误 [英] How to know if a cell has an error in the formula in C#

查看:115
本文介绍了如何知道,如果一个单元具有在C#公式中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在可以使用Excel公式 = ISERR(A1) = ISERROR(A1)

In an Excel formula you can use =ISERR(A1) or =ISERROR(A1)

在VBA宏,您可以使用 ISERROR(sheet.Cells(1,1))

In a VBA macro you can use IsError(sheet.Cells(1, 1))

但使用VSTO的Excel加载项项目中,我并没有发现类似功能的Microsoft.Office.Interop.Excel API之下。我只是想知道是否有在单元格中的错误,我不是在错误的类型很感兴趣。

But using a VSTO Excel Addin project I did not found similar function under the Microsoft.Office.Interop.Excel API. I only want to know if there is an error in the cell, I'm not really interested in the type of error.

我目前的解决方法是为所有现有的错误信息做到这一点:

My current workaround is to do this for all the existing error messages.:

if (((Range)sheet.Cells[1, 1]).Text == "#N/A" || ...)

有没有更好的方法来做到这一点。有没有在API中一个简单的函数是什么?

Is there a better way to do this. Is there a simple function in the API for that?

推荐答案

您可以使用 WorksheetFunction 方法:

Globals.ThisAddIn.Application.WorksheetFunction.IsErr(...)

[Your Excel Object].WorksheetFunction.IsErr(...)

ISERR 在语义上等同于Excel工作表函数,而不是只在单元格引用传递实际值 - AFAIK

The IsErr is semantically identical to the Excel worksheet function, only instead of the cell reference pass in the actual value - AFAIK.

这篇关于如何知道,如果一个单元具有在C#公式中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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