Foxtable(狐表)用户栏目专家坐堂 → excel报表中如何获取字体的宽度和高度?


  共有2272人关注过本帖平板打印复制链接

主题:excel报表中如何获取字体的宽度和高度?

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


加好友 发短信
等级:狐精 帖子:3353 积分:24705 威望:0 精华:0 注册:2012/3/26 21:47:00
  发帖心情 Post By:2017/9/23 17:17:00 [只看该作者]

例子确实没问题 但是代码改了以后放到我的项目里就不行  我只修改了这个判断条件 其他都没改
 Dim rg As MSExcel.Range
                Dim tempWs = wb.WorkSheets.Add
                Dim tempCell As MSExcel.Range = tempWs.Cells(1, 1)
                Dim Strike As Boolean
                For Each rg In ws.UsedRange
                    If rg.MergeCells AndAlso rg.MergeArea.Columns.count>1  Then
                        '' rg.Font.Strikethrough = Strike '设置删除线
                        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
                        tempcell.Value = rg.Value
                        tempcell.RowHeight = 0
                        tempcell.EntireRow.Activate
                        tempcell.EntireRow.AutoFit
                        If (rg.RowHeight < tempcell.RowHeight) Then
                            Dim tempHeight As Double
                            Dim tempCount As Integer
                            tempHeight = tempcell.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 + 10
                                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
            


 回到顶部
总数 21 1 2 3 下一页