Issue with autofitRows

Hi,

I have a statment in my code that is generating and exeption

The following

objWB.Worksheets(0).AutoFitRows()

generates a Null reference exception (use new key word to create an object instance)

while other methods like

objWB.Worksheets(0).AutoFilter.Range = "A7:Q7"

works fine

Why is this the case ?

thanks

Hi,

Please download the latest version:
Aspose.Cells for .NET v7.0.1.6 and see if it works fine.

Otherwise, please provide us your complete source code and sample xls/xlsx file if any that could replicate this issue.

The code below the line is giving me a NullReferenceException error.

But when I comment out the following statment:

flag.All = True

the code works why???

----------------------------------------------

Dim w As New Workbook

w.Worksheets.Clear()

Dim i As Integer = w.Worksheets.Add()

For j = 0 To 10

w.Worksheets(i).Cells(j, 0).PutValue("car cat dog bob")

Next

Dim style As New Style

style.IsTextWrapped = True

Dim flag As New StyleFlag

flag.WrapText = True

style.Borders(BorderType.BottomBorder).LineStyle = CellBorderType.Thin

style.Borders(BorderType.TopBorder).LineStyle = CellBorderType.Thin

style.Borders(BorderType.LeftBorder).LineStyle = CellBorderType.Thin

style.Borders(BorderType.RightBorder).LineStyle = CellBorderType.Thin

flag.All = True

w.Worksheets(i).Cells.CreateRange("A1:A11").ApplyStyle(style, flag)

w.Worksheets(0).AutoFitRows()

w.Save("boo.xlsm", SaveFormat.Xlsm)

Hi,

You should set font to style, otherwise we cannot autofitrow on null font settings.

We will improve autofitrow using default font in workbook later when user does not set font.

Hi,

Please try the latest version:
Aspose.Cells for .NET v7.0.2.0
It works fine.

FYI:
It’s better to use Workbook.CreateStyle() than to use new Style to create a style object.