Free Support Forum - aspose.com

Need help for translation of function from Office Excel to Aspose.Excel

Hi

Cand some one translate this function to use Aspose.Excel instead of Office.Excel


'--------------------------------------------------------------------------------------------
Private Function AutoFitMergedCellRowHeight(rCell As Excel.Range)
Dim CurrentRowHeight As Single
Dim MergedCellRgWidth As Single
Dim CurrCell As Excel.Range
Dim ActiveCellWidth As Single
Dim PossNewRowHeight As Single
rCell.Activate
If rCell.MergeCells Then
With rCell.MergeArea
If .Rows.Count = 1 And .WrapText = True Then
CurrentRowHeight = .RowHeight
ActiveCellWidth = rCell.ColumnWidth
For Each CurrCell In rCell.Application.Selection
MergedCellRgWidth = CurrCell.ColumnWidth + MergedCellRgWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
.EntireRow.AutoFit
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = ActiveCellWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight > PossNewRowHeight, CurrentRowHeight, PossNewRowHeight)
End If
End With
End If
End Function
'--------------------------------------------------------------------------------------------

Hi,

Please try this:

Private Sub AutoFitMergedCellRowHeight(ByVal rCell As Range, ByVal sheet As Worksheet)
Dim columnWidth As Double = 0
Dim rowHeight As Double
Dim previousWidth As Double = 0
Dim i As Integer

If rCell.RowCount <> 1 Then
Return
End If
Dim cells As Cells = sheet.Cells
For i = rCell.FirstColumn To rCell.FirstColumn + range.ColumnCount- 1
columnWidth += cells.GetColumnWidth(i)
Next
previoseWidth = cells.GetColumnWidth(rCell.FirstColumn)

cells.SetColumnWidth(rCell.FirstColumn, columnWidth)
sheet.AutoFitRow(rCell.FirstRow)
cells.SetColumnWidth(rCell.FirstColumn, previousWidth)
rCell.Merge()

End Sub