We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

NullReferenceException on InsertRow

Thread ID:





58534 Mar 24,2007 04:52 PM UTC Mar 26,2007 04:53 AM UTC WinForms 3
Tags: XlsIO
Administrator [Syncfusion]
Asked On March 24, 2007 04:52 PM UTC

I have a pre-existing Excel file on my hard drive that has a sheet called "Trades".
If I try to call InsertRow on this sheet, I get a NullReferenceException, here is the code:

ExcelEngine engine = new ExcelEngine();
IApplication excelApplication = engine.Excel;
IWorkbook workbook = excelApplication.Workbooks.Open(templateFile);
IWorksheet tradesSheet = workbook.Worksheets["Trades"];
tradesSheet.InsertRow(row,1,ExcelInsertOptions.FormatAsAfter); //throws a NullReferenceException

Am I doing something wrong?

Thanks in advance

Administrator [Syncfusion]
Replied On March 24, 2007 04:58 PM UTC

p.s. the variable "row" on the last line is an int wih value 6

Administrator [Syncfusion]
Replied On March 24, 2007 05:10 PM UTC

Here is the whole Exception with the relevent stack segment (see the attached image of the error snapshot in visual studio):
Object reference not set to an instance of an object.
at Syncfusion.XlsIO.Implementation.Collections.WorkbookNamesCollection.InsertRemoveRowColumn(String strSheetName, Int32 index, Boolean bIsRemove, Boolean bIsRow, Int32 iCount)
at Syncfusion.XlsIO.Implementation.Collections.WorkbookNamesCollection.InsertRow(Int32 iRowIndex, Int32 iRowCount, String strSheetName)
at Syncfusion.XlsIO.Implementation.WorksheetImpl.InsertRow(Int32 iRowIndex, Int32 iRowCount, ExcelInsertOptions insertOptions)


Melba Winshia [Syncfusion]
Replied On March 26, 2007 04:53 AM UTC

Hi Adrian,

Thanks for your interest in Essential XlsIO.

Could you please send us the specific Excel file, which has a sheet called "Trades" that you are seeing the problem with? This would help us in investigating further on this issue.

You can also open a Direct-Trac incident so that the file remains confidential.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon