资源描述:
《VB将数据导出到EXCEL》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、'************************************************************************* '** '** VB将数据导出到EXCEL,没有安装EXCEL的一样也可以导出. '** '** 调用方式: s_Export2Excel(Ado.Recordset) 或 s_Export2Excel(Rds.RecordSet) '** 支持 Rds 与 Ado 的记录导出 '** '********************************
2、***************************************** '得到所有数据类型,有些数据类型EXCEL不支持,已经替换掉 Public Function f_FieldType$(ByVal sType&) Dim iRe$ Select Case sType Case 2, 3, 20 iRe = "int" Case 5 iRe = "float" Case 6
3、 iRe = "money" Case 131 iRe = "numeric" Case 4 iRe = "real" Case 128 iRe = "binary" Case 204 iRe = "varbinary" Case 11 iRe = "bit" Ca
4、se 129, 130 iRe = "char" Case 17, 72, 131, 200, 202, 204 iRe = "varchar" Case 201, 203 iRe = "text" Case 7, 135 iRe = "datetime" Case 205 iRe = "image"
5、Case 128 iRe = "timestamp" End Select f_FieldType = iRe End Function '导出ADO记录集到EXCEL Public Function f_Export2Excel(ByVal sRecordSet As ADODB.Recordset, ByVal sExcelFileName$ _ , Optional ByVal sTableName$, Optional ByVal sO
6、verExist As Boolean = False) As Boolean 'On Error GoTo lbErr Dim iConcStr, iSql$, iFdlist$, iDB As ADODB.Connection Dim iI&, iFdType$, j, TmpField, FileName Dim iRe As Boolean '检查文件名 If Dir(sExcelFileName) <> "" T
7、hen If sOverExist Then Kill sExcelFileName Else iRe = False GoTo lbexit End If End If '生成创建表的SQL语句 With sRecordSet For iI = 0 To .Fields.Count - 1 iFdType
8、= f_FieldType(.Fields(iI).Type) Select Case iFdType Case "char", "varchar", "nchar", "nvarchar", "varbinary" If .Fields(iI).DefinedSize > 255 Then iSql = iSql & ",[