Free Support Forum - aspose.com

AutoFitColumns in Excel file using Aspose.Cells for .NET in C#

--- Debug:
Module loaded licens for Aspose.Cells - 7.3.4.0
Creating Workbook; Table: Beløb, File: \\ADM.aarhuskommune.dk\MTM\Home_Dir\azteb29\KTP Webbolig\Beløb.xls, Type: xls
Create data, OK.
Autosize columns and rows.
ved KTP.WebBolig.Forms.Items.SaveList.CreateWorkbook(DataView View, String Tablename, String Filename, String FileExtension) i C:\Temp\WebBolig 2.0\Forms\Items\SaveList.cs:linje 242
ved Aspose.Cells.Worksheet.AutoFitColumns()

ved ??.?.AutoFitColumn(Cells , Int32 , Int32 , Int32 , Int32 , AutoFitterOptions )

ved ??.?.?(Graphics , Cells , Int32 , Int32 , Int32 , Int32 , AutoFitterOptions )

ved ??.?.?(?? , Int32 , RectangleF )

ved ?.?.?(String , Int32 , FontStyle )

System.NullReferenceException: Objektreferencen er ikke indstillet til en forekomst af et objekt.

--- Code:
The offending code in C:\Temp\WebBolig 2.0\Forms\Items\SaveList.cs, line 242
Where "sheet" is an Aspose.Cells.Worksheet, that has been populated with data.

241 try {
242 sheet.AutoFitColumns();
243 sheet.AutoFitRows();
244 } catch (Exception err) {
245 System.Diagnostics.Debug.WriteLine(err);
246 }

--- Comments:
The entire application is run from a local drive (C:\) on the PC, the user has administrator rights,
Therefore I don't believe this to be a trust issue (http://www.aspose.com/community/forums/permalink/440132/440132/showthread.aspx#440132)

On the assumption, that this might be due to certain fonts,
I have made a copy of the fonts installed on the PC in question.
It is a 200MB+ zip file, I am however hesitant to upload this file, because of copyright and redistribution issues.

--- Attchments:
The resulting .xls file is attached, obviously without autosized columns/rows.

Hi,

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

Please download and try the latest version.Aspose.Cells for .NET (Latest Version) It should fix your problem. If you still face a problem, let us know. We have tested your issue with the following code and it does not generate any exception.

C#


string Path = @“F:\Shak-Data-RW\Downloads\Bel%c3%b8b.xls”;


Workbook workbook = new Workbook(Path);

Worksheet worksheet = workbook.Worksheets[0];


worksheet.AutoFitColumns();