Solved

Compare Excel Cell Styles

Posted on 2008-10-10
3
948 Views
Last Modified: 2012-06-21
VB2005, Excel 2007

I'm creating a VB.NET application that compares the contents of two Excel worksheets on a cell by cell basis.  I have not problem doing things like comparing values, formulas, number formats, etc.  What I want to be able to compare that the formatting on two cells is exactly the same.

What I have done so far is create an Excel style variable for each cell.

Dim ws1Style As Excel.Style = Worksheet1.Cells(r, c).style
Dim ws2Style As Excel.Style = Worksheet2.Cells(r, c).style

What I want to do now is determine if the two styles are exactly the same.  How can I do this?  
0
Comment
Question by:tfewster500
  • 2
3 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 22687509
Hi tfewster500,

It won't work comparing Styles, I'm afraid. By default, all cells have the "Normal" style applied, regardless of the formatting applied. In general, Styles are used to apply specific formatting to a range of cells in a single operation, however, simply changing the font on a cell (using the Font property of the range) will have no effect on the Style.

You will need to compare each formatting property (Font, Borders, Interior, etc) of each cell seperately.

Regards,

Wayne
0
 
LVL 2

Expert Comment

by:madivad2
ID: 22692561
I'm not sure that this would work, I am away from my dev box so can't try it first, but if you created a custom class which populates just those cell formatting options you are interested in, then in the class initiation it could extract the relevant styles.

From there, it is a matter of comparing the classes to see if they are equal, remembering that the reference to the class will be different, but the comparative values will be the same. You could even write a custom method (of the class) to do this test for you
0
 
LVL 2

Accepted Solution

by:
madivad2 earned 500 total points
ID: 22692700
upon reflection, creating a class for just testing the styles is a bit of an overkill...

Just create your own method within your app that does the same thing, comparing the individual components of the style you'd like compared
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now