We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Worksheet.AutoFitColumn(x) crashes with an "Object reference not set to an instance of an object." error


I'm currently using Aspose.Cells for .NET ( I'm running the component within SharePoint 2010 on the .NET 2.0 Framework. Currently, when I use Worksheet.AutoFitColumn(x), I get the following error message (including thread).

Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.

Thread information:
Thread ID: 7
Is impersonating: False
Stack trace: at Š.š.’(String , Int32 , FontStyle )
at ’’.—.š(‘’ , Int32 , RectangleF )
at ’’.—.œ(Graphics , Cells , Int32 , Int32 , Int32 , Int32 , AutoFitterOptions )
at ’’.—.AutoFitColumn(Cells , Int32 , Int32 , Int32 , Int32 , AutoFitterOptions )
at Aspose.Cells.Worksheet.AutoFitColumn(Int32 columnIndex)
at LeapSeedCommon.DataManager.RecordSearch.InsertExcelExportHeader(Worksheet xDoc, LeapSeedSection ExportSec, String GroupSort)
at LeapSeedCommon.DataManager.RecordSearch.GenerateExcelExportFile(String SQL, String ExportOpt, Workbook aspApp, Int32 Section_ID, String GroupSort, Hashtable HashStyles, ReaderProvider rpLocal, ReaderProvider rpExt)
at LeapSeedCommon.DataManager.RecordSearch.ExportSearchResultsToExcel(ReaderProvider& rpLocal, ReaderProvider& rpExt, HttpResponse& Response)
at ASP._layouts_leapseed_data_manager_export_excel_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\template\layouts\leapseed\data_manager\export_excel.aspx:line 39
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Page.Render(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

It's worth noting I noticed this in Aspose 7.3.5 as well. Also, When I use the exact same code outside of SharePoint in a .NET 4.0 application, everything works fine. So I wouldn't be surprised if this issue is specific to how Aspose.Cells works with .NET 2.0.

Below is the function the error occurs in.

Protected Overridable Sub InsertExcelExportHeader( _
xDoc as Aspose.Cells.WorkSheet, _
ExportSec as LeapSeedSection, _
GroupSort as String _

Dim X as Integer ' Loop Variable
Dim realX as Integer ' Real Loop Variable

Dim aspApp = xDoc.Workbook

X = 0
FOR realX = 0 TO ExportSec.Elements.Length - 1

If GroupSort <> ExportSec.Elements(realX).FieldName Then
' EXCEL Specific.

xDoc.Cells(0, X).PutValue(ExportSec.Elements(realX).Label)

Dim xStyle As Aspose.Cells.Style = xDoc.Cells(0, X).GetStyle()
xStyle.Pattern = BackgroundType.Solid
xStyle.ForegroundColor = System.Drawing.Color.Black
xStyle.Font.Color = System.Drawing.Color.White
xStyle.HorizontalAlignment() = Aspose.Cells.TextAlignmentType.Center
xStyle.Font.Size = 12
xStyle.Font.IsBold = True
xDoc.Cells(0, X).SetStyle(xStyle)

xDoc.AutoFitColumn(X) <--------- ERROR OCCURS HERE
X += 1
End If

End Sub ' Field_Data

Please also note that I am not loading a template in; Aspose is starting with a blank worksheet.

I hope you can help. We'd really like to be able to sell your components for our projects.




Thanks for your posting and considering Aspose.Cells for .NET.

Please provide us your sample project that replicates your mentioned exception. We will run your project at our end and investigate this issue.

If the issue is fixable, we will provide you a modified sample code and in case it is an error, we will log it in our database, so that this issue could be fixed at the earliest.

Thanks for your prompt reply to my post. I actually couldn’t reproduce the issue in a .NET 2.0 console app, so I reviewed SharePoint’s security setup, and realized I’d disabled FullTrust in favor of DLL-by-DLL security. Once I added the following to my custom SharePoint security file, the Aspose.Cells for .NET DLL worked fine:

<IMembershipCondition class=“UrlMembershipCondition” version=“1”
Url="$AppDirUrl$/bin/Aspose.Cells.dll" />
<IMembershipCondition class=“UrlMembershipCondition” version=“1”
Url="$AppDirUrl$/bin/Aspose.Words.dll" />

My guess is Aspose.Cells for .NET must do something low level that requires deeper access than SharePoint’s default security allows.

So I hope this post helps others who are trying to use the component in SharePoint.




Thanks for considering Aspose.

That’s great. Your post and findings will be really helpful for other Aspose users. We appreciate your best interest for other Aspose users.

We also wish you a great 2013 year :).

If you face any other issue, please feel free to post on our forums, we will be glad to help you asap.