sauravinfy
sauravinfy

Reputation: 43

How to Read and validate data of a excel sheet through .NET

I have a excel sheet contains three columns Name, 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.

Upvotes: 0

Views: 407

Answers (2)

Johann Blais
Johann Blais

Reputation: 9469

Easier than interop, you may also use an OleDbConnection.

Here is an example

Upvotes: 1

Kevin Stricker
Kevin Stricker

Reputation: 17388

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}$"

Upvotes: 1

Related Questions