请教一个MSHFLEXGRID的问题
我想用MSHFLEXGRID显示一个表格,表格内容是我定义的二维数组data(10,10)的内容,请问这个程序怎么写?刚上手,这部分不太明白。请各位前辈指点一下,谢谢各位了~~~
程序代码:
Dim data() As String
Private Sub Form_Initialize()
Dim i As Integer, j As Integer, k As Integer
ReDim data(10, 10)
For i = 0 To 10
If i <> 0 Then
For j = 0 To 10
If j <> 0 Then
data(i, j) = i & " - " & j
Else
data(i, j) = i
End If
Next j
Else
For k = 0 To 10
data(i, k) = k
Next k
End If
Next i
End Sub
Private Sub Form_Load()
Dim i As Integer, j As Integer
MSHFlexGrid1.Rows = 10 + 1
MSHFlexGrid1.Cols = 10 + 1
For i = 0 To 10
For j = 0 To 10
MSHFlexGrid1.TextMatrix(i, j) = data(i, j)
Next j
Next i
End Sub

程序代码:
Private Sub cmdexposure_Click()
Dim intRowCounter As Integer
Dim intColCounter As Integer
intRowCounter = MSHFlexGrid1.Rows
intColCounter = MSHFlexGrid1.Cols
Call MSHFlexGrid_To_Excel(MSHFlexGrid1, intRowCounter, intColCounter, , "CC") 'MSHFlexGrid1
End Sub
程序代码:
Public Sub MSHFlexGrid_To_Excel(TheFlexgrid As MSHFlexGrid, TheRows As Integer, TheCols As Integer, Optional GridStyle As Integer = 1, Optional WorkSheetName As String)
Dim objXL As New Excel.Application
Dim wbXL As New Excel.Workbook
Dim wsXL As New Excel.Worksheet
Dim intRow As Integer ' counter
Dim intCol As Integer ' counter
If Not IsObject(objXL) Then
MsgBox "You need Microsoft Excel to use this function", vbExclamation, "Print to Excel"
Exit Sub
End If
'On Error Resume Next is necessary because
'someone may pass more rows
'or columns than the flexgrid has
'you can instead check for this,
'or rewrite the function so that
'it exports all non-fixed cells
'to Excel
On Error Resume Next
' open Excel
objXL.Visible = True
Set wbXL = objXL.Workbooks.Add
Set wsXL = objXL.ActiveSheet
' name the worksheet
With wsXL
If Not WorkSheetName = "" Then
.Name = WorkSheetName
End If
End With
' fill worksheet
'MsgBox TheRows
'MsgBox TheCols
For intRow = 1 To TheRows
For intCol = 1 To TheCols
With TheFlexgrid
wsXL.Cells(intRow, intCol).Value = .TextMatrix(intRow - 1, intCol - 1) & " "
End With
Next
Next
' format the look
For intCol = 1 To TheCols
wsXL.Columns(intCol).AutoFit
'wsXL.Columns(intCol).AutoFormat (1)
wsXL.Range("a1", Right(wsXL.Columns(TheCols).AddressLocal, 1) & TheRows).AutoFormat GridStyle
Next
End Sub
