Hi,
Im getting the following error when trying to export a GridControl to Excel using:
Syncfusion.GridExcelConverter.GridExcelConverterControl gecc = new Syncfusion.GridExcelConverter.GridExcelConverterControl();
gecc.GridToExcel(gridToExport.Model, xlsName);
Any ideas?
Thanks!
ERROR:
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Syncfusion.XlsIO.Base"
StackTrace:
at Syncfusion.XlsIO.Implementation.WorkbookImpl.ClearAll()
at Syncfusion.XlsIO.Implementation.WorkbookImpl.DisposeAll()
at Syncfusion.XlsIO.Implementation.WorkbookImpl.Close(Boolean SaveChanges, String Filename)
at Syncfusion.GridExcelConverter.GridExcelConverterControl.GridToExcel(GridModel grid, String fileName, ConverterOptions options)
at Syncfusion.GridExcelConverter.GridExcelConverterControl.GridToExcel(GridModel grid, String fileName)
at Exporter.ExportGrid(GridControl gridToExport, Boolean deleteXlsAfterAttach) in Exporter.cs:line 50
YG
Yavanaarasi G
Syncfusion Team
August 18, 2008 08:47 AM UTC
Hi Ross,
Thank you for your interest in Syncfusion products.
I am not able to reproduce the exception that you mentioned here. I have created the sample with your code snippet and tested the issue. Exporting a GridControl to Excel works without any exception. I have tested this issue in our latest version v6.3.0.30.
Here is the sample for your reference:
http://www.syncfusion.com/development/uploads/GridToExcel_12a3970e.zipPlease take a look into the above sample and if still the issue exists, could you please try reproducing it in the above sample and send us the modified sample so that we could sort out the cause of the issue and provide you a solution?
Also, please specify the Essential studio version in which the issue caused.
Regards,
G.Yavana
YG
Yavanaarasi G
Syncfusion Team
August 18, 2008 01:06 PM UTC
Hi Ross,
The issue with "NullReferenceException" may cause when the workbook is not properly closed and excel engine is not disposed. Please use the following:
[C#]
workbook.close();
excelEngine.ThrowNotSavedOnDestroy = false;
engine.Dispose();
converter.Dispose();
Please try this and let me know if the problem still exists.
Regards,
G.Yavana
UA
Usman Ahmad
October 6, 2008 04:02 PM UTC
Hi,
I get a similar problem.
I am using the Syncfusion.XlsIO dll in order to export a grouped grid view to excel.
This works fine in the Debug build, but not in the Release build. The following is an example of the stack trace...
Syncfusion.XlsIO.Implementation.WorksheetImpl.GetRecord(Int32 iRow, Int32 iColumn)
at Syncfusion.XlsIO.Implementation.RangeImpl.get_Record()
at Syncfusion.XlsIO.Implementation.RangeImpl.CreateStyle()
at Syncfusion.XlsIO.Implementation.RangeImpl.get_CellStyle()
at Syncfusion.GridExcelConverter.GridExcelConverterBase.CopyBrush(GridStyleInfo gridCell, IRange range)
at Syncfusion.GridExcelConverter.GridExcelConverterBase.CopyStyle(GridStyleInfo gridStyle, IRange destRange)
...
with error... Object reference not set to an instance of an object.
Like I said, it works perfectly well in Debug mode, but not in the Release build. I have also checked the differences in files in both directories, and they are fine i.e. there does not exist a file in the Release build that exists in the Debug build.
I very much appreciate your help on this
>Hi Ross,
The issue with "NullReferenceException" may cause when the workbook is not properly closed and excel engine is not disposed. Please use the following:
[C#]
workbook.close();
excelEngine.ThrowNotSavedOnDestroy = false;
engine.Dispose();
converter.Dispose();
Please try this and let me know if the problem still exists.
Regards,
G.Yavana
GM
Geetha M
Syncfusion Team
October 8, 2008 06:17 AM UTC
Hi Usman,
Thank you for your interest in Syncfusion products.
This error may occur if the Excel engine is not disposed properly. So, as said in the previous update, could you please try disposing it?
Please let me know if you still face any issues.
Regards,
Geetha
MP
Markus Persson
October 14, 2008 01:59 PM UTC
Sometimes so do I have the same problem. I said "sometimes" since it occasionally works fine. I mostly get this error when I select an already existing excel file that I want to replace. As you will see in my code, I do not use ExcelEngine.
I'm using version 6.2.0.40 of Syncfusion.
My code is as follow (VB .Net):
Dim sfd As SaveFileDialog = New SaveFileDialog()
sfd.Filter = "Excel (*.xls)|*.xls"
sfd.DefaultExt = ".xls"
If sfd.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim gecc As Syncfusion.GridExcelConverter.GridExcelConverterControl = New Syncfusion.GridExcelConverter.GridExcelConverterControl()
gecc.ExportStyle = False
gecc.GridToExcel(Me.gcTest, sfd.FileName, Syncfusion.GridExcelConverter.ConverterOptions.RowHeaders)
gecc.Dispose()
If MessageBox.Show("Do you wish to open the xls file now?", "Export to Excel", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Dim proc As Process = New Process()
proc.StartInfo.FileName = sfd.FileName
proc.Start()
End If
End If
Error message:
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Syncfusion.XlsIO.Base"
StackTrace:
at Syncfusion.XlsIO.Implementation.WorksheetImpl.GetXFIndex(Int32 iRow, Int32 iColumn)
at Syncfusion.XlsIO.Implementation.WorksheetImpl.InnerGetCell(Int32 column, Int32 row)
at Syncfusion.XlsIO.Implementation.RangeImpl.get_Item(Int32 row, Int32 column)
at Syncfusion.XlsIO.Implementation.RangeImpl.get_Item(Int32 row, Int32 column, Int32 lastRow, Int32 lastColumn)
at Syncfusion.GridExcelConverter.GridExcelConverterControl.GridToExcel(GridModel grid, IWorksheet sheet, ConverterOptions options)
at Syncfusion.GridExcelConverter.GridExcelConverterControl.GridToExcel(GridModel grid, String fileName, ConverterOptions options)
at Syncfusion.GridExcelConverter.GridExcelConverterControl.GridToExcel(GridControl grid, String fileName, ConverterOptions options)
MP
Markus Persson
October 14, 2008 02:18 PM UTC
I forgot to mention that it's on this row that I recieve the error message:
gecc.GridToExcel(Me.gcTest, sfd.FileName, Syncfusion.GridExcelConverter.ConverterOptions.RowHeaders)
GM
Geetha M
Syncfusion Team
October 15, 2008 10:32 AM UTC
Hi Markus,
Thank you for the details.
This was a known issue with Essential Studio Volume 2. But this has been fixed in our latest release. Could you please consider upgrading to the latest version?
You can get the details of our latest release from the below forum thread:
http://www.syncfusion.com/support/forums/message.aspx?MessageID=77065Please let me know if you have any concerns.
Regards,
Geetha
PH
Pat Hayward
February 6, 2009 02:49 PM UTC
After bashing my head on this problem (or very similar) and talking with Usman I believe I've found the answer. Yes, putting in an engine.Dispose() call in after you close the book fixes the random null reference exceptions. But so does putting in a call to engine.ToString(). What I believe is happening is that in a release build the compiler/garbage collector is destroying the engine or some internal object it refers to while it is still required by the conversion process. Putting in a call to the engine object at the end keeps it hanging around.
AD
Administrator
Syncfusion Team
November 24, 2009 08:20 PM UTC
i.e. check that the variable storing the reference to the engine object doesn't go out of scope so that the GC thinks it can destroy it
If you call Engine.[anything] at the end of your code then that means you must have had a reference to it. That's why .Dispose & .ToString both do the trick
MK
Manoj Kumar G M
Syncfusion Team
June 14, 2013 05:40 AM UTC
Hi Mike,
Thank you for the details.
The above reported issue fix has been included in our new version 11.2.0.25. So please upgrade your essential studio version to our latest version.
We have provided the latest version download link for your reference.
Please let us know if you need any clarification.
Regards,
Manojkumar.