Free Support Forum -

Issue with autofitRows


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

The following


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 ?



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


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

For j = 0 To 10

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


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.Save("boo.xlsm", SaveFormat.Xlsm)


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.


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

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