简体   繁体   English

有没有办法验证excel中的单元格值(vsto)

[英]Is there any way for Validating cell value in excel (vsto)

Suppose i have some value in excel cell,its type may be anything date,numeric or string and i want that cell to be validated against its type ... Is there any way of doing this ? 假设我在excel单元格中有一些值,它的类型可能是日期,数字或字符串 ,我希望该类型的单元格与其类型进行验证 ......有没有办法做到这一点? thanks in advance.. 提前致谢..

I assume you mean that you have contents in a cell, which could be either a date, a double, or a plain string, and that you want to assert what corresponding .NET type it is. 我假设你的意思是你有一个单元格中的内容,可以是日期,双重或普通字符串,并且你想要断言它对应的.NET类型。 I believe there is no direct way of doing this. 我相信没有直接的方法可以做到这一点。 One approach would be to retrieve the Value2 in the cell, and try to cast it to each of these types, starting from the most restrictive one, until the cast works - ie DateTime (DateTime.FromOADate), then double (Convert.ToDouble), then string - and then apply the validation rule that applies to the particular type you found. 一种方法是在单元格中检索Value2,并尝试将其转换为这些类型中的每一种,从最严格的一个开始,直到转换为止 - 即DateTime(DateTime.FromOADate),然后是double(Convert.ToDouble) ,然后是字符串 - 然后应用适用于您找到的特定类型的验证规则。
I am not quite sure what you mean by validation, though, and what that would buy you. 我不太确定你的验证是什么意思,以及那会给你带来什么。 Once you know the type of the content, what would you do with it? 一旦你知道了内容的类型,你会用它做什么?

I use Excel's data validation technique in a VSTO application myself. 我自己在VSTO应用程序中使用Excel的数据验证技术。 It obviously isn't VSTO but it works well enough. 它显然不是VSTO,但它运作良好。 There are some drawbacks like you can't have multiple validations on the same cell (ie you have to know what your validating for) 有一些缺点,例如你不能在同一个单元格上进行多次验证(即你必须知道你的验证是什么)

You can directly use the excel's functionality !!! 你可以直接使用excel的功能! no need of any coding for that !! 不需要任何编码!!

instead of hard work go for the smart work ... 而不是努力工作去聪明的工作......

In excel, Go to the cell where you want the validation to come 在excel中,转到要进行验证的单元格

Menu ->> Data --> validation 菜单 - >>数据 - >验证

Here you can directly use the various excel validation terms. 在这里,您可以直接使用各种Excel验证条款。 Which you can refer here or.. 您可以在这里参考或..

http://support.microsoft.com/kb/211485 http://support.microsoft.com/kb/211485

Thanx Regards. Thanx问候。

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

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