Microsoft Office Tutorials and References
In Depth Information
Regular expressions
The preceding example shows the implementation of the simple multiplication
formula for two cells in the worksheet. You can perform more complex and
challenging calculations using this formula in Excel. Applying the formulae using
VSTO brings you the great advantage of applying them at runtime, and also based
on conditions.
Regular expressions
Regular expressions give a short, flexible, and snappy way of recognizing strings
of text, such as characters, words, or patterns. There is no specific feature available
in VSTO 3.0 for regular expressions. VSTO allows you to use most of the .NET
framework's namespaces and classes. In VSTO, you can use regular expression
with the help of .NET programming.
The following is an example for email validation applied to an Excel cell using
regular expression techniques for the Excel 2007 document-level solution.
Open Visual Studio 2008 and create a new solution with all the supporting files for the
development of the Excel solution. Write the following code in the Sheet1.cs file:
private void Sheet1_Startup(object sender, System.EventArgs e)
// Setting the value in the cell
Globals.Sheet1.Range["A1", missing].Value2 =
// Loading the cell value to the string
string strCellData = Globals.Sheet1.Range["A1",
// Validating the RegEx for email string
if (EmailValidate(strCellData) == true)
// String display in the cell
Globals.Sheet1.Range["B1", missing].Value2 =
"Email Address is Valid";
// String display in the cell
Globals.Sheet1.Range["B1", missing].Value2 =
"Email Address is Not Valid";
// Regular Expression validation function
Search JabSto ::

Custom Search