Solved

Compare Excel Cell Styles

Posted on 2008-10-10
3
954 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

756 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