让vb6的数据表格可以输出多层表头

来源:互联网 发布:积分怎么编程 编辑:程序博客网 时间:2024/05/22 09:51

现在使用 vb6 多为维护老程序。

vb6 自身提供的数据表格有 datagrid、MSHFlexGrid 等,其中 MSHFlexGrid 需要添加引用。

多数情况下数据表格都需要提供更复杂的布局,其中多层表头就是一种常用的格式。

通过 google 搜索,发现多数的解决方法是用外部控件,此类控件通常价格不菲,优缺点就不说了。这里介绍发现并改进的一种用 MSHFlexGrid 实现多层表头的办法,——不用花钱,而且很简单。

 

    With Me.MSHFlexGrid_MonthReport
        .Cols = 11
        .Rows = 3
       
        .ColWidth(0) = 500
       
        For i_ = 0 To .Cols - 1
            .ColAlignmentFixed(i_) = 4
        Next
       
        For i_ = 1 To 3
            .TextMatrix(0, i_) = "常项"
        Next
       
        .TextMatrix(0, 4) = "上期"
       
        For i_ = 5 To 10
            .TextMatrix(0, i_) = "本期"
        Next
       
        .TextMatrix(0, 0) = "序号"
        .TextMatrix(1, 0) = "序号"
        .TextMatrix(1, 1) = "品牌"
        .TextMatrix(1, 2) = "型号"
        .TextMatrix(1, 3) = "颜色"
        .TextMatrix(1, 4) = "上期库存"
        .TextMatrix(1, 5) = "本期入库"
        .TextMatrix(1, 6) = "本期出库"
        .TextMatrix(1, 7) = "本期销售"
        .TextMatrix(1, 8) = "内部现金销售"
        .TextMatrix(1, 9) = "其他"
        .TextMatrix(1, 10) = "期末库存"
       
        .MergeCells = flexMergeRestrictRows
        .MergeRow(0) = True
        '.MergeRow(1) = True
        .MergeCol(0) = True
    End With

基本道理是设置两个固定行(MSHFlexGrid的默认表头),然后再这两行使用合并。

原创粉丝点击