这是把flexgrid显示的转换为电子表格的程序你参考一些Private Sub Export2Excel(FlexGrid As Object)
'/*数据输出到Excel
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) '/*开始充入数据
Dim i As Long
Dim j As Integer
'/*设置页边距
With xlSheet.PageSetup
.leftmargin = ileftmargin / unit / 0.35
.rightmargin = irightMargin / unit / 0.35
.topmargin = itopMargin / unit / 0.35
.bottommargin = ibottomMargin / unit / 0.35
End With
With FlexGrid
'/*设置列宽
For j = 0 To .cols - 1
xlSheet.Columns(j + 1).ColumnWidth = .ColWidth(j) / unit / 3.5
Next j
For i = 0 To .rows - 1
For j = 0 To .cols - 1
xlSheet.Cells(i + 1, j + 1).value = "'" & .TextMatrix(i, j)
Next j
prg.value = i / (.rows - 1) * 100
Next i
End With
xlApp.Visible = True
Screen.MousePointer = vbDefault
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
prg.value = 0
Exit Sub
err_proc:
Screen.MousePointer = vbDefault
MsgBox "请确认您的电脑已安装Excel!", vbExclamation, "提示"
End Sub
'/*数据输出到Excel
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) '/*开始充入数据
Dim i As Long
Dim j As Integer
'/*设置页边距
With xlSheet.PageSetup
.leftmargin = ileftmargin / unit / 0.35
.rightmargin = irightMargin / unit / 0.35
.topmargin = itopMargin / unit / 0.35
.bottommargin = ibottomMargin / unit / 0.35
End With
With FlexGrid
'/*设置列宽
For j = 0 To .cols - 1
xlSheet.Columns(j + 1).ColumnWidth = .ColWidth(j) / unit / 3.5
Next j
For i = 0 To .rows - 1
For j = 0 To .cols - 1
xlSheet.Cells(i + 1, j + 1).value = "'" & .TextMatrix(i, j)
Next j
prg.value = i / (.rows - 1) * 100
Next i
End With
xlApp.Visible = True
Screen.MousePointer = vbDefault
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
prg.value = 0
Exit Sub
err_proc:
Screen.MousePointer = vbDefault
MsgBox "请确认您的电脑已安装Excel!", vbExclamation, "提示"
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货