我想一般情况下设置EXCEL默认行高为30,如果内容多再根据内容控制EXCEL自动换行。
我设置了下面的属性
With xlSheet.Range(C1, C2)
     .Borders.LineStyle = xlContinuous
     .RowHeight = 30
     .WrapText = True
     .Font.Size = 10
End With
可是内容多的情况下,EXCEL不能自动换行。
如果我去掉.RowHeight = 30,EXCEL能自动换行, 但是EXCEL的行高是默认的14.25,很小,达不到效果。
请问怎么改才能达到效果呢?

解决方案 »

  1.   

    代码来自http://bingning.net/free/source/programing/xlssetwordwrap.html#Region "文字的改行、缩小表示设定"
         ''' <summary>
         ''' 文字的改行、缩小表示设定
         ''' </summary>
         ''' <param name="iRowS">开始行号码</param>
         ''' <param name="iColS">开始列号码</param>
         ''' <param name="iRowE">结束行号码</param>
         ''' <param name="iColE">结束列号码</param>
         ''' <param name="bWrapText"></param>
         ''' <param name="bShrinkToFit"></param>
         ''' <returns></returns>
         ''' <res></res>
         Public Function xlsSetWordWrap(ByVal iRowS As Integer, ByVal iColS As Integer, _
                                        ByVal iRowE As Integer, ByVal iColE As Integer, _
                                        ByVal bWrapText As Boolean, ByVal bShrinkToFit As Boolean) As XLS_RESULT
             Try
                 oRange = oSheet.Range(Me.GetXlsRange(iColS) & iRowS.ToString, Me.GetXlsRange(iColE) & iRowE.ToString)
                 oRange.WrapText = bWrapText
                 oRange.ShrinkToFit = bShrinkToFit             MRComObject(oRange)         Catch ex As Exception
                 Me.XlsFileRelease()
                 Return XLS_RESULT.XLS_NG
             Finally
                 MRComObject(oRange)
             End Try
         End Function
     #End Region