比较vb.net Windows应用程序中的excel模板 [英] compare excel templates in vb.net Windows Application

查看:141
本文介绍了比较vb.net Windows应用程序中的excel模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请分享任何链接或代码...

我有一个Excel模板,用户可以在其中填写.然后,我有一个Web应用程序,允许用户上传Excel文件.我想知道是否有人知道如何验证用户上传的Excel文件是否遵循与我相同的Excel模板格式

我该如何比较两个excel文件?

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?

推荐答案

您必须打开每个工作簿,然后比较定义为每个单元格的相关属性值相同格式".您的问题是一般要比这更详细.
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.


公共函数CheckFormat(ByVal ImportedFile作为DataTable,ByVal TemplateFile作为DataTable)作为布尔值
昏暗的dtFileTable作为DataTable = ImportedFile
Dim dtTmplateTable As DataTable = TemplateFile
昏暗lbResult为布尔值= True
试试
如果dtFileTable.Columns.Count = dtTmplateTable.Columns.Count然后
昏暗liColCount为整数= 0
对于liColCount = 0到dtFileTable.Columns.Count-1
如果LCase(dtFileTable.Columns(liColCount).Caption)= LCase(dtTmplateTable.Columns(liColCount).Caption)然后
继续进行
其他
lsFormatStatus =上传的文件格式不正确
lbResult =假
退出
如果结束
下一个

如果是lbResult,则
如果不是(dtFileTable.Rows.Count> = 1),则
lsFormatStatus =上传的文件没有数据
lbResult =假
如果结束
如果结束
其他
lsFormatStatus =上传的文件格式不正确"
lbResult =假
如果结束
异常捕获
''objDB.LogError(ex)
lsFormatStatus =上传的文件格式不正确"

lbResult =假
结束尝试
返回lbResult
最终功能

私有Sub btnsubmit_Click(ByVal发送者作为System.Object,ByVal e作为System.EventArgs)处理btnsubmit.Click
Dim lsPath As String = txtPath.Text.Trim()
lblmsg.Text ="
将loDSTemplate调暗为新的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;" & _
数据源=& lsPath和;扩展属性= Excel 8.0;"
''''您必须在电子表格中引用的对象之后使用
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


将loDBExcelTemplate设置为新的System.Data.OleDb.OleDbDataAdapter("SELECT * FROM ["& xlsSheet.Name&"
after the object you reference in the spreadsheet
Dim loDBExcelTemplate As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" & xlsSheet.Name & "


这篇关于比较vb.net Windows应用程序中的excel模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆