如何使用 .NET 验证 Excel 范围是否存在错误/警告?

发布于 2024-08-26 00:34:49 字数 226 浏览 2 评论 0原文

我想验证 Excel 工作表的范围(例如“A10:B20”)以检查它是否有错误或 NA 值?在 C# 中如何做到这一点?

PS我发现类似的主题(Excel范围使用问题(单元格错误检查))但那个主题不是我需要的。

I want to validate range of excel worksheet (e.g. "A10:B20") to check that is it has error or NA value or not? How to do that in C#?

P.S. I find similar topic (Excel range usage question (cell error checking)) but that topic is not thing I need.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谢绝鈎搭 2024-09-02 00:34:49

关键是检查单元格中保存的值的数据类型。如果数据类型是整数 (Int32),则保存的值是 CVErr 值。要检查#N/A,单元格将是整数数据类型(不是双精度型!),保存值 -2146826246。

有关更多详细信息,请参阅堆栈溢出问题 如何知道 C# 中的公式是否有错误

The key is to check for the data type of the value held in the cell. If the data type is an Integer (Int32), then the value held is a CVErr value. To check for #N/A, the cell would be an Integer data type (not a Double!) holding the value -2146826246.

For more details, see the stack overflow question How to know if a cell has an error in the formula in C#.

茶底世界 2024-09-02 00:34:49

这可能对您有帮助。首先从 Excel 中读取数据。请参阅此堆栈溢出问题。 将 Excel 范围转换为 ADO.NET 数据集或数据表等。然后迭代数据表中的每一行,例如

    foreach (DataRow row in sheetTable.Rows)
    {
        foreach (DataColumn column in sheetTable.Columns)
        {
            // Check what ever you want to check
            if (row[column].ToString().Equals("Error") || row[column] ==null)
            {
                // do something
            }
        }
    }

This might help you.First read the data from the excel.Please see this stack over flow question. Convert Excel Range to ADO.NET DataSet or DataTable, etc. Then iterate each row from the data table like

    foreach (DataRow row in sheetTable.Rows)
    {
        foreach (DataColumn column in sheetTable.Columns)
        {
            // Check what ever you want to check
            if (row[column].ToString().Equals("Error") || row[column] ==null)
            {
                // do something
            }
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文