G
Guest
I picked up the following code posted by a MVP at some newsgroup. I am using
the code to compare excel files. It works great for considerable changes but
when the difference in the excel files is quite minor (for instance if I
change only one or less than 10 cells in one file), the comparison fails to
pick up the differences. Any thoughts? (Code below)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim abyt1() As Byte = {12, 55, 88, 32}
Dim abyt2() As Byte = {12, 55, 88, 32}
Dim fs As IO.FileStream
fs = New IO.FileStream("File1.xls", IO.FileMode.Open)
ReDim abyt1(fs.Length)
fs = New IO.FileStream("File2.xls", IO.FileMode.Open)
ReDim abyt2(fs.Length)
Dim IsDifferent As String = CType(ArrayDif(abyt1, abyt2), String)
System.Windows.Forms.MessageBox.Show(IsDifferent)
End Sub
Public Function ArrayDif(ByVal array1() As Byte, ByVal array2() As Byte)
As Boolean
Dim Hash1() As Byte = New
MD5CryptoServiceProvider().ComputeHash(array1)
Dim Hash2() As Byte = New
MD5CryptoServiceProvider().ComputeHash(array2)
For i As Int64 = 0 To Math.Min(Hash1.Length, Hash2.Length) - 1
If Hash1(i) <> Hash2(i) Then
Return False
Exit Function
End If
Next
Return True
End Function
the code to compare excel files. It works great for considerable changes but
when the difference in the excel files is quite minor (for instance if I
change only one or less than 10 cells in one file), the comparison fails to
pick up the differences. Any thoughts? (Code below)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim abyt1() As Byte = {12, 55, 88, 32}
Dim abyt2() As Byte = {12, 55, 88, 32}
Dim fs As IO.FileStream
fs = New IO.FileStream("File1.xls", IO.FileMode.Open)
ReDim abyt1(fs.Length)
fs = New IO.FileStream("File2.xls", IO.FileMode.Open)
ReDim abyt2(fs.Length)
Dim IsDifferent As String = CType(ArrayDif(abyt1, abyt2), String)
System.Windows.Forms.MessageBox.Show(IsDifferent)
End Sub
Public Function ArrayDif(ByVal array1() As Byte, ByVal array2() As Byte)
As Boolean
Dim Hash1() As Byte = New
MD5CryptoServiceProvider().ComputeHash(array1)
Dim Hash2() As Byte = New
MD5CryptoServiceProvider().ComputeHash(array2)
For i As Int64 = 0 To Math.Min(Hash1.Length, Hash2.Length) - 1
If Hash1(i) <> Hash2(i) Then
Return False
Exit Function
End If
Next
Return True
End Function