如何MSFlexGrid数据导出到excel

白开水20010216 2005-11-03 09:15:13
如何将MSFlexGrid中显示的数据导出到excel表或者是txt文件中啊?
...全文
202 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
faysky2 2005-11-05
  • 打赏
  • 举报
回复
不过用完了记得关闭对象和释放对象:
Public Sub Export(formname As Form, flexgridname As String)
......
xlApp.Quit
Set xlShell = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
intocsdn 2005-11-05
  • 打赏
  • 举报
回复
学习
饮水需思源 2005-11-03
  • 打赏
  • 举报
回复
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
With formname.Controls(flexgridname)
For i = 0 To .Rows - 1
For j = 0 To .Cols - 1
xlSheet.Cells(i + 1, j + 1).value = "'" & .TextMatrix(i, j)
Next j
Next i
End With
xlApp.Visible = True
Screen.MousePointer = vbDefault
Exit Sub
Err_Proc:
Screen.MousePointer = vbDefault
MsgBox "请确认是否已安装Excel!", vbExclamation, "提示"

End Sub
winehero 2005-11-03
  • 打赏
  • 举报
回复
逐行读取MSFlexGrid的各单元格数据,对EXcel用Excel对象,对Txt文档以写模式Open后逐行
写入就完了。

1,451

社区成员

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

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