不明白你的意思,EXCEL也不能做到真正的任意(一个表格5行*5列,你把最左上和最右下的合并试试,可能吗?)VSFLEXGRID已经做够用了,可能你的用法不对,请把你的要求说详细一点才好帮你。其实你也可以用OLE技术使用EXCEL来做你的程序中的表格,这样你的要求可能会得到很好的满足。

解决方案 »

  1.   

    不用第三方控件
    MSHFlexGrid
      

  2.   

     MSHFlexGrid 
    MergeCol、MergeRow 属性
          返回或设置一个值,决定哪些行和列可以把它们的内容合并。要使用 MergeCells 属性,这些属性必须为 True。语法object.MergeCol(number) [=Boolean]
    object.MergeRow(number) [=Boolean]MergeCol 和 MergeRows 属性的语法包含如下部分:部分 描述 
    Object 一个对象表达式,其值为“应用于”列表中的一个对象。 
    number 一个 Long值,指定 MSHFlexGrid 中的列或行。 
    Boolean 一个 Boolean值,指定当相邻单元显示相同内容时合并是否发生。 
    设置值Boolean 的设置值如下所示:部分 描述 
    True 当相邻单元显示相同内容时,行向左合并或列向上合并。 
    False 当相邻单元显示相同内容时,单元不合并。这是 MergeCol 和 MergeRow 缺省设置值。 
    说明如果 MergeCells 属性被设置为非零值,具有相同值的相邻单元,只有它们都在一行并且 MergeRow 属性被设置为 True,或都在一列且 MergeCol 属性被设置为 True 时才合并。关于 MSHFlexGrid 的合并功能的详细信息,请参阅 MergeCells 属性。 
    MergeCells 属性
          返回或设置一个值,决定包含相同内容的单元是否应该跨越多行或多列分组在一个单个单元中。语法object.MergeCells [=value]MergeCells 属性的语法包含如下部分内容:部分 描述 
    object 一个对象表达式,其值为“应用于”列表中的一个对象。 
    value 一个整数或常数,指定单元分组(合并)。如设置值中所指定。 
    设置值value 的设置值如下所示:常数 值 描述 
    flexMergeNever 0 不显示。包含相同内容的单元不分组。这是缺省设置。 
    flexMergeFree 1 自由。包含相同内容的单元总是合并。 
    flexMergeRestrictRows 2 限制行。只有行中包含相同内容的相邻单元(向当前单元左边)才合并。 
    flexMergeRestrictColumns 3 限制列。只有列中包含相同内容的相邻单元(向当前单元上方)才合并。 
    flexMergeRestrictBoth 4 限制行和列。只有在行中(向左)或在列中(向上)包含相同内容的单元才合并。 
    说明合并单元的能力使得您能够以一种清晰、简明的方式显示数据。可以连同排序和 MSHFlexGrid 的列序函数一起合并使用单元。要使用 MSHFlexGrid 的单元合并能力: 把 MergeCells 设置为除 0 以外的一个值。(设置值之间的区别在示例中解释。)
    为要合并行和列把 MergeRow 和 MergeCol 的数组属性设置为 True。 
    当使用单元合并能力时,MSHFlexGrid 合并包含相同内容的单元。无论什么时候单元的内容更改,合并都自动的更新。当 MergeCells 被设置为除 0 (不显示)以外的一个值时,突出显示的选择自动关闭。这样做是为加速重画,也是因为包含合并单元范围的选择可能导致不可预料的结果。
      

  3.   

    同意lihonggen0(用VB),我也用过这个控件
      

  4.   

    MSHFlexGrid 
    MergeCol、MergeRow 属性
    可以搞定!!
    同意lihonggen0(用VB)
      

  5.   

    '************  vsflexgrid  **************
    MergeCells Property
    See Also     Examples     Applies to     Returns or sets whether cells with the same contents will be merged into a single cell.
    Syntax     
    [form!]VSFlexGrid.MergeCells[ = MergeSettings ]
    Res    
    The MergeCells property is used in conjunction with the MergeRow, MergeCol, and MergeCompare properties to control whether and how cells are merged for display. Merging cells allows you to display data in a clear, appealing way because it highlights groups of identical information. It also gives you flexibility to build tables similar to the ones you can create in HTML or using Microsoft Word, both of which support merged cells.To create tables with merged cells, you must set the MergeCells property to a value other than flexMergeNever, and then set the MergeRow and MergeCol properties to True for the rows and columns you wish to merge (except when using the flexMergeSpill mode). After these properties are set, the control will automatically merge neighboring cells that have the same contents. Whenever the cell contents change, the control updates the merging state.The algorithm used to compare cell contents and determine whether they should be merged is set through the MergeCompare property.The settings for the MergeCells property are described below:Constant Value Description
    flexMergeNever 0 Do not merge cells.
    flexMergeFree 1 Merge any adjacent cells with same contents (if they are on a row with RowMerge set to True or a column with MergeCol set to True).
    flexMergeRestrictRows 2 Merge rows only if cells above are also merged.
    flexMergeRestrictColumns 3 Merge columns only if cells to the left are also merged.
    flexMergeRestrictAll 4 Merge cells only if cells above or to the left are also merged.
    flexMergeFixedOnly 5 Merge only fixed cells. This setting is useful for setting up complex headers for the data and preventing the data itself from being merged.
    flexMergeSpill 6 Allow long entries to spill into empty adjacent cells.
    flexMergeOutline 7 Makes entries in subtotal rows spill to fill adjacent empty cells.  This setting is useful when you want to display only a node name on the outline nodes and data on the regular (non-node) rows.The flexMergeSpill setting is a little different from the others. It is the only setting that does not require you to set the MergeCol and MergeRow properties, and that does not merge cells with identical settings. Instead, it allows cells with long entries to spill into adjacent cells as long as they are empty. This is often useful when creating outlines. You may use a narrow column to hold group titles, which can then spill into the cells to the right. The picture below shows an example using the flexMergeSpill setting. Notice how some cells with long entries spill into adjacent empty cells or get truncated if the adjacent cell is not empty:
    The difference between the Free and Restricted settings is whether cells with the same contents should always be merged (Free settings) or only when adjacent cells to the left or to the top are also merged.  The examples below illustrate the difference.    ' regular spreadsheet view
        fg.MergeCells  = flexMergeNever
        fg.MergeCol(0) = True: fg.MergeCol(1) = True: fg.MergeCol(2) = True
        fg.MergeCol(3) = False
        ' free merging: notice how the first region cell (East) merges 
        ' across employees (Donna and John) to its left.
        fg.MergeCells  = flexMergeFree
        fg.MergeCol(0) = True: fg.MergeCol(1) = True: fg.MergeCol(2) = True
        fg.MergeCol(3) = False
        ' restricted merging: notice how the first region cell (East)
        ' no longer merges across employees to its left.
        fg.MergeCells  = flexMergeRestrictAll
        fg.MergeCol(0) = True: fg.MergeCol(1) = True: fg.MergeCol(2) = True
        fg.MergeCol(3) = FalseData Type
    MergeSettings (Enumeration)
    Default Value
    flexMergeNever (0)