没有合适的资源?快使用搜索试试~ 我知道了~
VB60_导出excel_方法源代码
3星 · 超过75%的资源 需积分: 9 17 下载量 85 浏览量
2013-05-22
15:52:17
上传
评论
收藏 8KB TXT 举报
温馨提示
试读
6页
VB6.0导出excel的方法源代码,可方便读取excel的数据
资源推荐
资源详情
资源评论
方法一:
用Msflexgrid的Textmatrix属性取Msflexgrid中每一个单元格的内容,然后填到Excel表中,或者写成CSV格式
方法二:
直接把查询结果导出成Excel工作表
Public Sub Export(formname As Form, flexgridname As String)
Dim xlApp As Object 'Excel.Application
Dim xlBook As Object 'Excel.Workbook
Dim xlSheet As Object 'Excel.Worksheet
Screen.MousePointer = vbHourglass
On Error GoTo Err_Proc
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
'Begin to fill data to sheet
Dim i As Long
Dim j As Integer
Dim k As Integer
With formname.Controls(flexgridname)
For i = 0 To .rows - 1
k = 0
For j = 0 To .Cols - 1
If .colwidth(j) > 20 Or .colwidth(j) < 0 Then
k = k + 1
xlSheet.Cells(i + 1, k).Value = "'" & .TextMatrix(i, j)
End If
Next j
Next i
End With
xlApp.Visible = True
用Msflexgrid的Textmatrix属性取Msflexgrid中每一个单元格的内容,然后填到Excel表中,或者写成CSV格式
方法二:
直接把查询结果导出成Excel工作表
Public Sub Export(formname As Form, flexgridname As String)
Dim xlApp As Object 'Excel.Application
Dim xlBook As Object 'Excel.Workbook
Dim xlSheet As Object 'Excel.Worksheet
Screen.MousePointer = vbHourglass
On Error GoTo Err_Proc
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
'Begin to fill data to sheet
Dim i As Long
Dim j As Integer
Dim k As Integer
With formname.Controls(flexgridname)
For i = 0 To .rows - 1
k = 0
For j = 0 To .Cols - 1
If .colwidth(j) > 20 Or .colwidth(j) < 0 Then
k = k + 1
xlSheet.Cells(i + 1, k).Value = "'" & .TextMatrix(i, j)
End If
Next j
Next i
End With
xlApp.Visible = True
Screen.MousePointer = vbDefault
Exit Sub
Err_Proc:
Screen.MousePointer = vbDefault
MsgBox "请确认您的电脑已安装Excel!", vbExclamation,"提示"
End Sub
===================================
Public Function ExporToExcel(strOpen As String)
'*********************************************************
'* 名称:ExporToExcel
'* 功能:导出数据到EXCEL
'* 用法:ExporToExcel(sql查询字符串)
'*********************************************************
Dim Rs_Data As New ADODB.Recordset
Dim Irowcount As Integer
Dim Icolcount As Integer
Dim cn As New ADODB.Connection
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlQuery As Excel.QueryTable
With Rs_Data
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;Collate=Machine;BackgroundFetch=no;Exclusive=No;SourceType=DBF;SourceDB=D:\DBF;"
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.Source = strOpen
Exit Sub
Err_Proc:
Screen.MousePointer = vbDefault
MsgBox "请确认您的电脑已安装Excel!", vbExclamation,"提示"
End Sub
===================================
Public Function ExporToExcel(strOpen As String)
'*********************************************************
'* 名称:ExporToExcel
'* 功能:导出数据到EXCEL
'* 用法:ExporToExcel(sql查询字符串)
'*********************************************************
Dim Rs_Data As New ADODB.Recordset
Dim Irowcount As Integer
Dim Icolcount As Integer
Dim cn As New ADODB.Connection
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlQuery As Excel.QueryTable
With Rs_Data
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;Collate=Machine;BackgroundFetch=no;Exclusive=No;SourceType=DBF;SourceDB=D:\DBF;"
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.Source = strOpen
剩余5页未读,继续阅读
资源评论
- sandy88772016-10-08不实用,性能不好。
- jangpenny2014-02-10测试编译环境为win7 64位,可以用,但是功能太简单
jshaxcsy
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 徐州市区shp边界文件
- 简易数字频率计设计(原理图、PCB、源码、分析报告)
- 20225207038罗丽文财管专2201班.rar
- Golang:通过Gin框架+Redis+责任链,实现一个简单的钉钉机器人,进行消息处理 ps:多应用版
- 基于cnn和AlexNet的铝材缺陷检测内含数据集和demo原型2种方法
- 2023年各城市PM2.5, PM10, SO2, NO2等环境空气质量数据
- go 语言 实现的 使用modbus 协议 通过DTU tcp 链接 采集数据
- SHELL脚本(全是干货)
- Windows屏幕录屏软件
- 2022年各城市PM2.5, PM10, SO2, NO2等环境空气质量数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功