关于将MSFlexGrid中的数据导出到Excel的问题
我在将MSFlexGrid中的数据导出到Excel时,遇到以下问题:
1、怎么合并excel中的单元格?
2、怎么设置excel某列的宽度?
3、怎么格式化某列数据(对齐方式或者日期数值格式设置)?
。。。。。
我尝试了以ExcelSheet.Cells.Merge的方法及属性都不行,可能是不大会用。
我的函数如下:
Public Function flexgridToExcel(flexgrd As MSFlexGrid, dtlRow As Integer) As Excel.Worksheet
If flexgrd.Rows = flexgrd.FixedRows Then
Set flexgridToExcel = Null
Exit Function
End If
Dim ExcelApp As New Excel.Application
Dim ExcelBook As New Excel.Workbook
Dim ExcelSheet As New Excel.Worksheet
Dim i As Long
Dim L As Long
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelBook = ExcelApp.Workbooks.Add(1)
Set ExcelSheet = ExcelBook.Worksheets(1)
ExcelApp.Visible = True
' ExcelSheet.Cells.AutoFit
' ExcelSheet.Cells.AutoFormat
' ExcelSheet.Cells.Merge
Dim col As Integer
For i = 0 To flexgrd.Rows - 1
col = 0
For L = 1 To flexgrd.Cols - 1
If flexgrd.ColWidth(L) > 0 Then
col = col + 1
' ExcelSheet.Cells(i +dtlRow, col).Width = flexgrd.ColWidth(L)
ExcelSheet.Cells(i + dtlRow, col) = flexgrd.TextMatrix(i, L) & ""
End If
Next L
Next i
Set flexgridToExcel = ExcelSheet
End Function