How to Read and validate data of a excel sheet through .NET
I have a excel sheet contains three columns N开发者_如何学JAVAame, Email ID and Contact No. I would like to read data from a excel data and check through my code that the Email ID column contains @ sign, Contact No should be of maximum 10 digits, I would like to do these types of validation. Please suggest.
Easier than interop, you may also use an OleDbConnection.
Here is an example
Read up on the Interop.Excel namespace if you want to get data from Excel files.
If you want something a bit better than using Interop, I use GemBox.Spreadsheet. You'll want to use another library if it's something you need to deploy to a computer which doesn't have Excel installed.
You can use regular expressions to validate strings. Read up on the System.Text.RegularExpressions namespace to figure that one out.
A simple regular expression to check for at least one @ sign in a string would be: @"@"
To check that a string consists of exactly 1-10 digits: @"^\d{1,10}$"
精彩评论