以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]Excel数据导入前的校验,帮忙改下代码,谢谢 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=84485) |
||||
-- 作者:浙江仔 -- 发布时间:2016/5/3 16:17:00 -- [求助]Excel数据导入前的校验,帮忙改下代码,谢谢 想在Excel数据导入时,做一下校验,是否包含那几项,但是老是提示有问题,不知大怎么处理了,望指教,谢谢! Dim dlg As New OpenFileDialog dlg.Filter = "Excel文件|*.xls" dlg.MultiSelect = False \'不允许选择多个文件 If dlg.ShowDialog =DialogResult.OK Then Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) Dim nms() As String = {"姓名","身份证号码","单位","培训日期","培训类型","培训项目"} Dim idds() As String For n As Integer = 0 To Sheet.Cols.Count -1 idds(n) = Sheet(0,n).Value Next Dim iscontains = False For Each nm As String In nms Output.Show(nm) If array.indexof(idds, nm) < 0 Then iscontains = False Exit For End If Next If iscontains = False Then messagebox.show("所选文件部分必选字段缺少,无法导入!") Return "所选文件部分必选字段缺少,无法导入!" End If End If
|
||||
-- 作者:大红袍 -- 发布时间:2016/5/3 16:24:00 -- Dim dlg As New OpenFileDialog dlg.Filter = "Excel文件|*.xls" dlg.MultiSelect = False \'不允许选择多个文件 If dlg.ShowDialog =DialogResult.OK Then Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) Dim nms() As String = {"姓名","身份证号码","单位","培训日期","培训类型","培训项目"} Dim idds(Sheet.Cols.count-1) As String For n As Integer = 0 To Sheet.Cols.Count -1 idds(n) = Sheet(0,n).Value Next Dim iscontains = True For Each nm As String In nms Output.Show(nm) If array.indexof(idds, nm) < 0 Then msgbox(nm) iscontains = False Exit For End If Next If iscontains = False Then messagebox.show("所选文件部分必选字段缺少,无法导入!") Return "所选文件部分必选字段缺少,无法导入!" End If End If |
||||
-- 作者:浙江仔 -- 发布时间:2016/5/3 16:27:00 -- 谢谢 |
||||
-- 作者:浙江仔 -- 发布时间:2016/5/3 16:28:00 -- 顺便问一句,袍哥还是袍姐 |