Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
My problem statement is to compare two excels. Values, formatting,etc and show the differences cell wise.
I could compare values and formula using arrays which is very quick.

Is there a way to compare cell formatting too in a better way than looping cells?
I need to get the source value, target value,and the address where there is a difference
I tried the following way and its takes ages to print result.Please help


C#
public void Compare(Microsoft.Office.Interop.Excel.Range rngSourceRange, Microsoft.Office.Interop.Excel.Range rngTargetRange)
       {
           Range tgtCell = null;
           foreach (Range srcCell in rngSourceRange.Cells)
           {
               tgtCell = (Range)rngTargetRange.Cells[srcCell.Row, srcCell.Column];

               //Font
               ReflectiveCompare(srcCell.Font, tgtCell.Font);
           }
       }



C#
public void ReflectiveCompare<T>(T x, T y)
       {
           foreach (MemberInfo m in typeof(T).GetMembers(BindingFlags.GetProperty))
           {
               if (m.MemberType == MemberTypes.Property)
               {
                   var prop = (PropertyInfo)m;
                   string[] arry = new string[] { "FontStyle", "Background", "Color", "Size", "Name", "Strikethrough", "Subscript", "Superscript" };
                   if (arry.Contains(prop.Name))
                   {
                       if (prop.CanRead && prop.GetGetMethod().GetParameters().Length == 0)
                       {
                           var xValue = prop.GetValue(x, null);
                           var yValue = prop.GetValue(y, null);
                           if (!xValue.Equals(yValue))
                           {
                              //.. print difference
                           }
                       }
                   }
                   else  continue;
               }
           }

       }
Posted
Comments
[no name] 9-Sep-14 11:17am    
i don't know :| :@

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900