Foxtable(狐表)用户栏目专家坐堂 → 代码问题


  共有5120人关注过本帖平板打印复制链接

主题:代码问题

帅哥哟,离线,有人找我吗?
刘林
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1936 积分:14844 威望:0 精华:0 注册:2016/4/28 9:58:00
代码问题  发帖心情 Post By:2016/11/12 13:44:00 [只看该作者]

Dim dlg As new OpenFileDialog
dlg.Filter = "Excel|*.xls;*.xlsx"
If dlg.ShowDialog = DialogResult.OK Then
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    Dim bmh As Integer
    Dim ksh As Integer
    Dim xm As Integer
    Dim sw As Integer
    Dim dl As Integer
    Dim njdm As Integer
    Dim bj As Integer
    Dim xxmc As Integer
    For i As Integer = 0 To sheet.Cols.count -1
        If sheet(0,i).value = "报名号"
            bmh =i
        End If
        If sheet(0,i).value = "考试号"
            ksh = i
        End If
        If sheet(0,i).value = "xm"
            xm = i
        End If
        If sheet(0,i).value ="生物"
            sw = i
        End If
        If sheet(0,i).value ="地理"
            dl = i
        End If
        If sheet(0,i).value ="年级代码"
            njdm = i
        End If
        If sheet(0,i).value ="班级"
            bj = i
        End If
        If sheet(0,i).value = "学校名称"
            xxmc = i
        End If
    Next
    Tables("成绩").StopRedraw()
    For n As Integer = 1 To Sheet.Rows.Count -1
        Dim bmh1 As String = sheet(n,bmh).value.replace(" ","").replace(chr(9),"")
        Dim xm1 As String = sheet(n,xm).value.replace(" ","").replace(chr(9),"")
        Dim bj1 As String = sheet(n,bj).value.replace(" ","").replace(chr(9),"")
        Dim njdm1 As String = sheet(n,njdm).value.replace(" ","").replace(chr(9),"")
        Dim xxmc1 As String = sheet(n,xxmc).value.replace(" ","").replace(chr(9),"")
        Dim dr As DataRow = DataTables("成绩").sqlFind("单位名称 = '" & xxmc1 & "'and 姓名 = '" & xm1 & "'And 考试名称 = '" & e.form.Controls("ComboBox2").value & "' And 年级代码 = '" & njdm1 & "' And 班级 = '" & bj1 & "'")
        '     If dr Is Nothing Then '如果不存在同考号的行
        '         dr =  DataTables("学生信息").AddNew()
        '     End If
        For m As Integer = 0 To sheet.Cols.count -1
            Select Case sheet(0,m).value
                Case "生物"
                    dr("生物_A") = sheet(n,m).value
                Case "地理"
                    dr("地理_A") = sheet(n,m).value
                Case "报名号","考试号"
                    dr(sheet(0,m).value) = Sheet(n,m).Value.replace(" ","").replace(chr(9),"")
            End Select
            
        Next
    Next
    Tables("成绩").ResumeRedraw()
DataTables("成绩").save()
End 
老师,我有成绩表,另有一个生物地理EXCL表结构如下
报名号 考试号 姓名 生物 地理 年级代码 班级 学校名称
175902137001 170213604 曹洪图 16 39 14 03 内江市东兴区石子镇中心学校

想按年级,班级,学校名称,考试名称,姓名,将生物,地理成绩导入到生物_A,地理_B,现写出上面代码不够简洁,另外还有错误提示:未设置对象变量或 With 块变量。请问错在哪里,如何更简洁,谢谢


 回到顶部
总数 12 1 2 下一页