Foxtable(狐表)用户栏目专家坐堂 → [求助]自动行高没有作用


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

主题:[求助]自动行高没有作用

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


加好友 发短信
等级:六尾狐 帖子:1348 积分:9833 威望:0 精华:0 注册:2015/6/30 8:46:00
[求助]自动行高没有作用  发帖心情 Post By:2019/4/28 21:50:00 [只看该作者]

   如一红色代码,自动行高没有效果,
 Dim App As New MSExcel.Application
    Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
    Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
    Dim Rg As MSExcel.Range = Ws.Range("8:" & tb.Rows.Count + 8)
    Rg.EntireRow.AutoFit  '自动调整行高
    App.Visible = True
    ws.PrintOut(ActivePrinter:= e.Form.Controls("V_Com打印机").text)
    wb.save
    app.Quit

 

图片点击可在新窗口打开查看此主题相关图片如下:微信图片_20190428213139.png
图片点击可在新窗口打开查看
[此贴子已经被作者于2019/4/28 21:51:41编辑过]

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


加好友 发短信
等级:六尾狐 帖子:1348 积分:9833 威望:0 精华:0 注册:2015/6/30 8:46:00
  发帖心情 Post By:2019/4/29 7:53:00 [只看该作者]

顶一下


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/4/29 10:02:00 [只看该作者]

1、试试

 

    Dim App As New MSExcel.Application
    Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
    Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
    Dim Rg As MSExcel.Range = Ws.Range("8:" & tb.Rows.Count + 8)
    Rg.WrapText = True
    Rg.EntireRow.AutoFit  '自动调整行高
    App.Visible = True
    'ws.PrintOut(ActivePrinter:= e.Form.Controls("V_Com打印机").text)
    'wb.save
    'app.Quit

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/4/29 10:20:00 [只看该作者]

2、试试这样调整行高

 

Dim App As New MSExcel.Application
try
    Dim Wb As MSExcel.WorkBook = app.WorkBooks.open("c:\aaa.xls")
    Dim rg As MSExcel.Range
    Dim Ws = wb.WorkSheets(1)
    Dim tempWs = wb.WorkSheets.Add
    For Each rg In ws.UsedRange
        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
    Next
    app.DisplayAlerts = False
    tempWs.Delete
    app.visible = True
catch ex As exception
    msgbox(ex.message)
    app.quit
End try


 回到顶部