| 网站首页 | VB.Net实例分析 | .Net技术文摘 | 下载中心 | VB.Net书籍笔记 | .Net源码 | VBS脚本与组件调用 | Windows2008技术文摘 | 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> VB.Net实例分析 >> 其他 >> 实例分析正文
最新推荐 更多内容
VB.Net Excel合并单元格的实例
VB.Net Excel合并单元格的实例
作者:njtmcpm    来源:njtmcpm的专栏     更新时间:2009-9-4

 VB.Net Excel合并单元格的代码:

    Sub MergeCell(ByRef theSheet As Excel.Worksheet, ByVal startRow As Integer, ByVal endRow As Integer, ByVal particularCol As Integer)
        Dim intStartRow As Integer
        Dim intEndRow As Integer
        Dim theCol As Integer 'declare the particular column

        'the line of sart and end are detrived from procedure
        ''''''''''''''''''''''''''''''''''''
        'intStartRow = 4
        'intEndRow = 101
        'theCol = 1
        intStartRow = startRow
        intEndRow = endRow
        theCol = particularCol
        '''''''''''''''''''''''''''
        Dim flagRow As Integer
        Dim i As Integer  'the exteral surround
        Dim j As Integer  'the interal round
        i = intStartRow
        flagRow = intStartRow
        With theSheet
            Do While i <= intEndRow
                For j = i + 1 To intEndRow
                    If .Cells(i, theCol).Value = .Cells(j, theCol).Value Then
                    Else
                        ' MsgBox flagRow & "行与" & j - 1 & "行的数据一致!"
                        '   i = j
                        If flagRow <> j - 1 Then  '标志与当前行不一致时合并
                            'MsgBox transIntToChar(theCol) & flagRow & ":" & transIntToChar(theCol) & j - 1
                            .Range(transIntToChar(theCol) & flagRow & ":" & transIntToChar(theCol) & j - 1).Merge()
                        End If
                        flagRow = j 'vb.net源码和实例,来自乐博网 www.lob.cn
                        Exit For
                    End If
                Next
                i = j
                '看是否到最后了,如果到了最后,则退出外层循环
                If i > intEndRow Then
                    'MsgBox flagRow & "行与" & j - 1 & "行的数据一致!"
                    If flagRow <> j - 1 Then  '标志与当前行不一致时合并
                        ' MsgBox transIntToChar(theCol) & flagRow & ":" & transIntToChar(theCol) & j - 1
                        .Range(transIntToChar(theCol) & flagRow & ":" & transIntToChar(theCol) & j - 1).Merge()
                    End If
                    Exit Do
                End If
            Loop
        End With
    End Sub

    Function transIntToChar(ByVal kk As Integer) As String
        '将数字转换为Excel工作表中的表示列的字母
        transIntToChar = Chr(Asc("A") + kk - 1)
    End Function

 

  • 上一篇:

  • 下一篇:
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    VB.Net数据自增的3个实例
    VB.Net在Excel工作簿中使用Chart宿主控件显示图表
    VB.Net为excel取消用户密码的实例
    VB.Net为excel设置用户密码的实例
    VB.Net把excel导出XPS文件
    VB.Net把excel导出PDF文件的实例
    VB.Net把excel导入Access数据库
    VB.Net把excel导入文本文件的实例
    VB.Net把excel导入XML文件的实例
    VB.Net显示和隐藏Excel操作窗格的实例
    VB.Net输出Word和Excel报表的实例

    | 设为首页 | 加入收藏 | 联系站长 | | 友情链接 | 版权申明 |
    乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]