error "An entry with the same key already exists" when create new cell

Dec 18, 2010 at 2:09 AM
Edited Dec 18, 2010 at 2:13 AM

I use new version of NPOI and I coded in my application like that

(reading an exits excel file, does not create new one)

Dim row As HSSFRow
row = sheet.GetRow(currentRowIndex)

 Dim oCell As HSSFCell
 oCell = row.CreateCell(columnIndex)

if Cell at (currentRowIndex, columnIndex) has already exits it will through an error like this

"An entry with the same key already exists."

Error in Detail:

   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.TreeSet`1.Add(T item)
   at System.Collections.Generic.SortedDictionary`2.Add(TKey key, TValue value)
   at NPOI.HSSF.UserModel.HSSFRow.AddCell(Cell cell)
   at NPOI.HSSF.UserModel.HSSFRow.CreateCell(Int32 columnIndex, CellType type)
   at NPOI.HSSF.UserModel.HSSFRow.CreateCell(Int32 column)

   at Inct.ExportReport.GenerateDataTemplate(DataView dvSource, Int32 iSheet, Int32 iCurrentDataRow) in D:\CongViec\DU_AN\Export to Excel\Excel_Report7_Inct\ExportReport.vb:line 422
   at Inct.ExportReport.InitExport(String autoZip, ExportType& _exportType) in D:\CongViec\DU_AN\Export to Excel\Excel_Report7_Inct\ExportReport.vb:line 150
   at Inct.ExportReport.Export(String xml_path, String form_id, Dictionary`2 list_para, String autoZip, ExportType& _exportType) in D:\CongViec\DU_AN\Export to Excel\Excel_Report7_Inct\ExportReport.vb:line 73
   at Inct.WebForm1.cmdExport3_Click(Object sender, EventArgs e) in D:\CongViec\DU_AN\Export to Excel\Excel_Report7_Inct\AppPage\WebForm1.aspx.vb:line 49
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)



I solved this problem provisionally with this

"IsNot Nothing" in VB.Net means "!= null" in C#

                       Dim oCell As HSSFCell
                        If (row.GetCell(columnIndex) IsNot Nothing) Then 
                            oCell = row.GetCell(columnIndex)
                            oCell = row.CreateCell(columnIndex)
                        End If


Thanks for the good project