在VB处理数据显示的时候,使用表格是一种好的方法,虽然DataGrid可以与数据源绑定,但是总有美中不足,就是外观不好看,所以有时应用MsFlexGrid显示数据还是一种比较好的方法,以下几个函数是用来控制MsFlexGrid的程序
(本人语言表达能力有限,还请见谅)
'MsFlexGrid操作函数'合并列Public Function MergeCol(GridObj As Object, ByVal StartCol As Long, ByVal EndCol As Long, ByVal ColValue As String, ByVal CurrentRow As Long) As BooleanIf StartCol > EndCol Or StartCol > GridObj.Cols Or CurrentRow > GridObj.Rows Then MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title MergeCol = False Exit FunctionEnd IfFor I = StartCol To EndColGridObj.MergeCol(I) = TrueGridObj.TextArray(faIndex(GridObj, CurrentRow, I)) = ColValueGridObj.ColAlignment(I) = flexAlignCenterCenterNext IGridObj.MergeRow(CurrentRow) = TrueMergeCol = TrueEnd Function'合并行Public Function MergeRow(GridObj As Object, ByVal StartRow As Long, ByVal EndRow As Long, ByVal RowValue As String, ByVal CurrentCol As Long) As BooleanIf StartRow > EndRow Or StartRow > GridObj.Rows Or CurrentCol > GridObj.Cols Then MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title MergeRow = False Exit FunctionEnd IfFor I = StartRow To EndRowGridObj.MergeRow(I) = TrueGridObj.TextArray(faIndex(GridObj, I, CurrentCol)) = RowValueGridObj.ColAlignment(CurrentCol) = flexAlignCenterCenterNext IGridObj.MergeCol(CurrentCol) = TrueMergeRow = TrueEnd Function'转换索引Public Function faIndex(GridObj As Object, ByVal row As Integer, ByVal col As Integer) As LongIf row > GridObj.Rows Or row < 0 Or col > GridObj.Cols Or col < 0 Then MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title faIndex = -1 Exit FunctionEnd IffaIndex = row * GridObj.Cols + colEnd Function'插入行Public Function SetItem(GridObj As Object, ByVal row As Integer, ByVal col As Integer, ByVal SetValue As String) As BooleanIf row > GridObj.Rows Or row < 0 Or col > GridObj.Cols Or col < 0 Then MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title SetItem = False Exit FunctionEnd If GridObj.TextArray(faIndex(GridObj, row, col)) = SetValue SetItem = TrueEnd Function'得到单元格值Public Function GetItem(GridObj As Object, ByVal row As Integer, ByVal col As Integer) As StringIf row > GridObj.Rows Or row < 0 Or col > GridObj.Cols Or col < 0 Then MsgBox "对不起,行列设置错误!", vbOKOnly, App.Title GetItem = "" Exit FunctionEnd If GetItem = GridObj.TextArray(faIndex(GridObj, row, col))End Function这是我以前写的几个函数,不知能不能帮上你, 我弄Excel时间挺长,有什么问题可以给我发E_mailw.hua@ynmail.com