Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.1 KiB

  1. Attribute VB_Name = "Exporter"
  2. Option Explicit
  3. Private Const ERROR_STRING_C As String = "!!!ERROR!!!"
  4. Public Sub Export2XL( _
  5. ByVal i_rs As ADODB.Recordset, _
  6. ByVal i_strFileName As String, _
  7. ByVal i_strTabName As String _
  8. )
  9. Dim cnn As ADODB.Connection
  10. Dim rs As ADODB.Recordset
  11. Dim fld As ADODB.Field
  12. Set cnn = New ADODB.Connection
  13. Set rs = New ADODB.Recordset
  14. cnn.Open "DRIVER=Microsoft Excel Driver (*.xls);ReadOnly=0;DBQ=" & i_strFileName & ";HDR=0;"
  15. cnn.Execute "Create table " & i_strTabName & p_GetFieldCreationInfo(i_rs)
  16. rs.Open "Select * from `" & i_strTabName & "$`", cnn, adOpenForwardOnly, adLockOptimistic
  17. If (i_rs.RecordCount > 0) Then
  18. i_rs.MoveFirst
  19. End If
  20. On Error Resume Next
  21. Do While (Not i_rs.EOF)
  22. rs.AddNew
  23. For Each fld In i_rs.Fields
  24. rs(fld.Name) = fld.Value
  25. If (Err.Number <> 0) Then
  26. Err.Clear
  27. If (fld.Type = adVarWChar) Then
  28. rs(fld.Name) = ERROR_STRING_C
  29. End If
  30. End If
  31. Next
  32. rs.Update
  33. i_rs.MoveNext
  34. DoEvents
  35. Loop
  36. End Sub
  37. Private Function p_GetFieldCreationInfo( _
  38. ByVal i_rs As ADODB.Recordset _
  39. ) As String
  40. Dim fld As ADODB.Field
  41. Dim str As String
  42. Dim blnFirstField As Boolean
  43. str = "("
  44. blnFirstField = True
  45. For Each fld In i_rs.Fields
  46. If (Not blnFirstField) Then
  47. str = str & ","
  48. Else
  49. blnFirstField = False
  50. End If
  51. str = str & fld.Name
  52. Select Case fld.Type
  53. Case adVarWChar
  54. str = str & " text"
  55. Case adInteger
  56. str = str & " long"
  57. Case adBoolean
  58. str = str & " bit"
  59. Case adDate
  60. str = str & " date"
  61. Case Else
  62. str = str & " text"
  63. End Select
  64. Next
  65. str = str & ")"
  66. p_GetFieldCreationInfo = str
  67. End Function