using Templates error

May 16, 2011 at 6:25 PM
Edited May 16, 2011 at 6:58 PM

So I tried using a template I got a weird problem

in the template file if there is a row which is all empty, then writing to a cell in that row produces a null reference exception.

                t_sheet1.GetRow(i).GetCell(1).SetCellValue(RemoteId); //row i = 2 is empty
                t_sheet1.GetRow(i).GetCell(2).SetCellValue(TailNumber);

problem is fixed by creating a dummy column and filling it with ids, or using CreateCell.

But  however when attempting to write to a file, I get the following error.

"Object reference not set to an instance of an object."

the write code is copied from the examples solution, pasted here:

            FileStream file = new FileStream(@"test.xls", FileMode.CreateNew);
            _hssfworkbook.Write(file);

and the full exception call stack is this:

   at NPOI.HPSF.VariantSupport.Write(Stream out1, Int64 type, Object value, Int32 codepage)
   at NPOI.HPSF.MutableProperty.Write(Stream out1, Int32 codepage)
   at NPOI.HPSF.MutableSection.Write(Stream out1)
   at NPOI.HPSF.MutableSection.CalcSize()
   at NPOI.HPSF.MutableSection.get_Size()
   at NPOI.HPSF.MutablePropertySet.Write(Stream out1)
   at NPOI.POIDocument.WritePropertySet(String name, PropertySet Set, POIFSFileSystem outFS)
   at NPOI.POIDocument.WriteProperties(POIFSFileSystem outFS, IList writtenEntries)
   at NPOI.HSSF.UserModel.HSSFWorkbook.Write(Stream stream)
   at WMONCommon.Report.WMONExcelMaker.WriteToFile() in C:\Q-DRIVE\Tasks\WGCM_Monitoring_Service\WMON\WMONMain\WMONCommon\Report\WMONExcelMaker.cs:line 65
   at WMONCommon.Report.WMONExcelMaker.CreateFile() in C:\Q-DRIVE\Tasks\WGCM_Monitoring_Service\WMON\WMONMain\WMONCommon\Report\WMONExcelMaker.cs:line 33
   at WMONConsole.CustomTests.Run_ExcelGen() in C:\Q-DRIVE\Tasks\WGCM_Monitoring_Service\WMON\WMONMain\WMONConsole\CustomTests.cs:line 94
   at WMONConsole.Program.Main(String[] args) in C:\Q-DRIVE\Tasks\WGCM_Monitoring_Service\WMON\WMONMain\WMONConsole\Program.cs:line 33
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

 

What am I doing wrong?

May 16, 2011 at 6:33 PM
Edited May 16, 2011 at 6:59 PM

 also thank you in advance for reading.