VB将MSHFlexGrid数据导出到Excel文件通用功能

1.通用导出Excel功能。

2.将 MSHFlexGrid数据导出到Excel文件通用功能。

3.具体代码如下:

'将下列代码保存到一模块文件中,调用方法:Export fgrid1,cd1

Public Sub Export(flexgridname As MSHFlexGrid, CD1 As CommonDialog)
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() 'Begin to fill data to sheet
Dim i As Long
Dim j As Integer
' With formname.Controls("flexgridname")
For i = To flexgridname.rows -
For j = To flexgridname.Cols -
xlSheet.Cells(i + , j + ).Value = "'" & flexgridname.TextMatrix(i, j)
Next j
Next i
' End With
xlApp.Visible = True
Screen.MousePointer = vbDefault
Exit Sub
Err_Proc:
Screen.MousePointer = vbDefault
'报错以后用老的导出函数
savef flexgridname, CD1
' 'MsgBox "请确认您的电脑已安装Excel!", vbExclamation, "提示" End Sub
上一篇:使用POI把查询到的数据表数据导出到Excel中,一个表一个sheet.最详细!!!


下一篇:bzoj2565: 最长双回文串