|
- Sub 导入学籍册()
- Dim cnn As Object, rs As Object
- Dim SQL As String, d As Object, arr(), i&, l&, j&, n&, t, s$
- Set d = CreateObject("scripting.dictionary")
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" & ThisWorkbook.Path & ";Exclusive=No;"
- Set rs = CreateObject("ADODB.Recordset")
- s = [J1]
- SQL = "select 学籍编号,姓名,性别,身份证号,出生年月,民族,班级,家庭住址,'',联系电话,备注 from z221801"
- If s <> "" And s <> "全部" Then SQL = SQL & " where left(学籍编号,10) like '%" & s & "'"
- rs.Open SQL, cnn, 1, 3
- With Sheets("学籍册")
- .UsedRange.Offset(3).ClearContents
- ReDim arr(1 To rs.RecordCount, 10)
- For i = 1 To rs.RecordCount
- d(rs.Fields(0).Value) = i
- For j = 0 To rs.Fields.Count - 1
- If j <> 8 Then arr(i, j) = rs.Fields(j).Value
- Next j
- rs.MoveNext
- Next i
- SQL = "select 学籍编号,监护人 from zj221800"
- If s <> "" And s <> "全部" Then SQL = SQL & " where left(学籍编号,10) like '%" & s & "'"
- Set rs = CreateObject("ADODB.Recordset")
- rs.Open SQL, cnn, 1, 3
- For i = 1 To rs.RecordCount Step 2
- For l = i To i + 1
- t = d(rs.Fields(0).Value)
- If Len(arr(t, 8)) = 0 Then
- If Len(rs.Fields(1).Value) And t <> "" Then arr(t, 8) = rs.Fields(1).Value
- End If
- rs.MoveNext
- Next l
- Next i
- .Range("a4").Resize(UBound(arr), 11) = arr
- End With
- rs.Close
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- End Sub
复制代码 |
|