Click here to Skip to main content
15,898,374 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Please Share any link or code...

I have a Excel Template where users can fill up. Then i have a web application that allows users to upload Excel files. I was wondering if anyone knows how i can verify if the Excel file uploaded by the user follows the same format of the Excel Template that i have

How can i compare tow excel files?
Posted
Updated 11-Jul-11 18:34pm
v2

You'd have to open each workbook, then compare the relevate property values of each and every cell that you define as the "same format". Your question is to general to go into any more detail than that.
 
Share this answer
 
Public Function CheckFormat(ByVal ImportedFile As DataTable, ByVal TemplateFile As DataTable) As Boolean
Dim dtFileTable As DataTable = ImportedFile
Dim dtTmplateTable As DataTable = TemplateFile
Dim lbResult As Boolean = True
Try
If dtFileTable.Columns.Count = dtTmplateTable.Columns.Count Then
Dim liColCount As Integer = 0
For liColCount = 0 To dtFileTable.Columns.Count - 1
If LCase(dtFileTable.Columns(liColCount).Caption) = LCase(dtTmplateTable.Columns(liColCount).Caption) Then
Continue For
Else
lsFormatStatus = "Uploaded File is not in Proper Format
lbResult = False
Exit For
End If
Next

If lbResult Then
If Not (dtFileTable.Rows.Count >= 1) Then
lsFormatStatus = "Uploaded File has no data
lbResult = False
End If
End If
Else
lsFormatStatus = "Uploaded File is not in Proper Format"
lbResult = False
End If
Catch ex As Exception
'objDB.LogError(ex)
lsFormatStatus = "Uploaded File is not in Proper Format"

lbResult = False
End Try
Return lbResult
End Function

Private Sub btnsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
Dim lsPath As String = txtPath.Text.Trim()
lblmsg.Text = ""
Dim loDSTemplate As New System.Data.DataSet()
xlsWB = xlsApp.Workbooks.Open(lsPath, False, False)
xlsSheet = xlsWB.Worksheets(1)
Me.Refresh()
lnktemplate.Text = String.Empty
Dim lsConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & lsPath & ";Extended Properties=Excel 8.0;"
''You must use the $ after the object you reference in the spreadsheet
Dim loDBExcelTemplate As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" & xlsSheet.Name & "$]", lsConn)
loDBExcelTemplate.TableMappings.Add("Table", "ExcelFile")
loDBExcelTemplate.Fill(loDSTemplate)
Dim Templated As DataTable = New DataTable
Templated.Columns.Add("IP")
Templated.Columns.Add("Port")
If CheckFormat(loDSTemplate.Tables(0), Templated) Then
(Do ping and telnet)
Else
Lblerror.text="Not in proper format"
C++
End Sub
 
Share this answer
 

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