如何MSFlexGrid数据导出到excel

白开水20010216 2005-11-03 09:15:13
如何将MSFlexGrid中显示的数据导出到excel表或者是txt文件中啊?
...全文
172 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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后逐行
写入就完了。
回复
相关推荐
发帖
控件
创建于2007-09-28

1425

社区成员

VB 控件
申请成为版主
帖子事件
创建了帖子
2005-11-03 09:15
社区公告
暂无公告