如何将MSHFlexGrid1控件中的数据写到EXCEL文件中,最好能给出详细说明!在线等待

tw4480 2002-06-11 03:16:03
如何将MSHFlexGrid1控件中的数据写到EXCEL文件中,最好能给出详细说明!在线等待
...全文
99 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tw4480 2002-06-11
  • 打赏
  • 举报
回复
谢谢!不过我是问如何将MSHFlexGrid1控件中的数据写到EXCEL文件中?也就是说涉及到MSHFlexGrid1的用法.
blueer 2002-06-11
  • 打赏
  • 举报
回复
Dim ex As Object
Dim i As Integer
Dim j As Integer
Dim XlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set XlApp = CreateObject("Excel.Application")
XlApp.Visible = True
Set xlBook = XlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)

Dim rst As Recordset
Set Cnn1 = New ADODB.Connection
Cnn1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Mode=Read|Write;Persist Security Info=False"
Cnn1.Open
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open SQL, Cnn1, adOpenKeyset, adLockOptimistic, adCmdText
rst.MoveFirst
For j = 0 To rst.RecordCount - 1
For i = 0 To rst.Fields.Count - 1
xlSheet.Cells(1, i + 1) = rst.Fields(i).Name
xlSheet.Cells(j + 2, i + 1) = rst.Fields(i).Value
Next i
rst.MoveNext
Next j
xlSheet.Columns.AutoFit

1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧