如何把MSFlexGrid表格里的内容导入到Excel?

xunqinji 2005-12-02 07:34:13
1.如何把MSFlexGrid表格里的内容导入到Excel?
2.如何把MSFlexGrid表格里的内容保存为.dat的文件格式?
...全文
214 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
上官云峰 2005-12-02
  • 打赏
  • 举报
回复
保存到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
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
faysky2 2005-12-02
  • 打赏
  • 举报
回复
Dim i As Long
Dim j As Integer
Dim strOut As String
Open "C:\Test.dat" For Out Put As #1
With MSFlexGrid1
For i = 0 To .Rows - 1
For j = 0 To .Cols - 1
strOut = strOut & .TextMatrix(i, j) & " "
Next j
Write #1, strOut
Next i
End With
Close #1
射天狼 2005-12-02
  • 打赏
  • 举报
回复
我的网站上有导入到EXCEL文件的代码,你可以看看。
至于存成dat文件的格式,你所说的dat是什么格式,文本文件吗?因为WINDOWS下的扩展名已经不能简单的标识文件格式了。

http://www.j2soft.cn/

VB资料->查询“将FlexGrid表格数据导入到Excel中”;

====================
免费的学习交流网站,欢迎大家访问!
http://www.j2soft.cn/
http://j2soft.008.net/

1,453

社区成员

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

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