以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助] 加了代码,还是不能自动行高  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=127674)

--  作者:mirco
--  发布时间:2018/11/19 20:31:00
--  [求助] 加了代码,还是不能自动行高
老师,加了代码,还是不能自动行高,应该出来深加工注意事项是3行显示,要3行的行高。请帮助!谢谢!
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:深加工订单.xls

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:订单.table


--  作者:mirco
--  发布时间:2018/11/19 20:48:00
--  

Dim Book As New XLS.Book(ProjectPath & "Attachments\\深加工订单.xls")
Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表
Dim fl As String = ProjectPath & "Reports\\深加工订单.xls"
Book.Build() \'生成细节
Book.Save(fl) \'保存工作簿

Dim App As New MSExcel.Application
try
    Dim Wb As MSExcel.WorkBook = app.WorkBooks.open(fl)
    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
Dim Proc As New Process
Proc.File = fl
Proc.Start()


--  作者:有点蓝
--  发布时间:2018/11/19 21:36:00
--  
……
Next
    app.DisplayAlerts = False
    tempWs.Delete
Wb.save
    app.visible = True
catch ex As exception
    msgbox(ex.message)
    app.quit
End try

--  作者:mirco
--  发布时间:2018/11/19 22:00:00
--  
可以了,谢谢老师,但是生成的报表都是否只读文件。
--  作者:有点蓝
--  发布时间:2018/11/19 22:27:00
--  
把任务管理器里所有word进程关闭,重新测试。测试的时候不要打开当前word文件