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
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];
ReflectiveCompare(srcCell.Font, tgtCell.Font);
}
}
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))
{
}
}
}
else continue;
}
}
}