Foxtable(狐表)用户栏目专家坐堂 → [求助]Excel报表中,对于合并的单元格,有什么办法自动调整行高?


  共有3002人关注过本帖树形打印复制链接

主题:[求助]Excel报表中,对于合并的单元格,有什么办法自动调整行高?

帅哥哟,离线,有人找我吗?
大红袍
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/10/20 14:04:00 [显示全部帖子]

Dim App As New MSExcel.Application
try
    Dim Wb As MSExcel.WorkBook = app.WorkBooks.open("d:\test.xls")
    Dim rg As MSExcel.Range
    Dim Ws = wb.WorkSheets(1)
    Dim tempWs = wb.WorkSheets.Add
    For Each rg In ws.UsedRange
        If rg.MergeCells Then
            Dim tempCell As MSExcel.Range
            Dim width As Double = 0
            Dim tempCol
            For Each tempcol In rg.MergeArea.Columns
                width = width + tempcol.ColumnWidth
            Next
            tempWs.Columns(1).WrapText = True
            tempWs.Columns(1).ColumnWidth = width
            tempWs.Columns(1).Font.Size = rg.Font.Size
            tempWs.Cells(1, 1).Value = rg.Value
            tempWs.Cells(1, 1).RowHeight = 0
            tempWs.Cells(1, 1).EntireRow.Activate
            tempWs.Cells(1, 1).EntireRow.AutoFit
            If (rg.RowHeight < tempWs.Cells(1, 1).RowHeight) Then
                Dim tempHeight As Double
                Dim tempCount As Integer
                tempHeight = tempWs.Cells(1, 1).RowHeight
                tempCount = rg.MergeArea.Rows.Count
                For Each addHeightRow As object In rg.MergeArea.Rows
                   
                    If (addHeightRow.RowHeight < tempHeight / tempCount) Then
                        addHeightRow.RowHeight = tempHeight / tempCount
                    End If
                    tempHeight = tempHeight - addHeightRow.RowHeight
                    tempCount = tempCount - 1
                Next
                rg.WrapText = True
            End If
        End If
    Next
    app.DisplayAlerts = False
    tempWs.Delete
    app.visible = True
catch ex As exception
    msgbox(ex.message)
    app.quit
End try


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/10/20 14:26:00 [显示全部帖子]

没办法。

 回到顶部