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. Image for the cookie policy date

NullReferenceException on InsertRow

Hi,
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
:)
Adrian

3 Replies

AD Administrator Syncfusion Team March 24, 2007 04:58 PM UTC

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


AD Administrator Syncfusion Team 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)

SyncfusionError4.zip


MW Melba Winshia Syncfusion Team 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.

Thanks,
Melba

Loader.
Live Chat Icon For mobile
Up arrow icon