求助,代码导入文件。如何判断选错后文件内字段错误,并给出提示
Dim App As New MSExcel.Application
Dim wb1 As MSExcel.WorkBook = App.WorkBooks.Open(ProjectPath & "wordup\" & strss)
Dim ws As MSExcel.WorkSheet = wb1.workSheets(1)
Dim Rg As MSExcel.Range = Ws.UsedRange
Dim ary = rg.value
Dim dt As DataTable = Functions.Execute("生成cmd数据表","考勤","")
dt.StopRedraw() '停止绘制
Dim nms1() As String
nms1 = New String() {"项目名称","1“,"2"}
'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题\
Dim val1 As Integer = 0
Dim valzc As Integer = 0
Dim valcm As Integer = 0
For n As Integer = 1 To rg.Rows.Count -1
next
[此贴子已经被作者于2024/4/29 9:10:32编辑过]
正确的文件 字段名字 是 1,2,3
错误的文件 字段名字 是 4,5
现在得操作方法是通过 上传文件,然后获取到上传文件的名字,进行对比。
上传文件的时候,没有办法判断是否选择是正确的文件。
在选错文件的时候,文件还能正常上传,因为字段不一样,导入数据的时候会报错。
遍历第一行所有列判断,比如
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("D:\Report.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.UsedRange
For j As Integer = 1 To Rg.Columns.Count
If Ws.Cells(1, j).value Like "*某列*" Then
msgbox(“包含某列”)
End If
Next