Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Sir/s,

Great day.

I'm new to open XML vb.net

I would like to know on how to assigned dummy value in cell.CellValue if
the cell.CellValue in openxml is nothing or null

I'm getting error when the function GetExcelEnumerator catches nothing in cellValue.

The error is 'Object reference not set to an instance of an object' when I debugged,

I found the value in cell.CellValue is nothing.

Thank you in advance for your kind help.

Here's my function code:



VB
Private Function GetExcelCellEnumerator(row As Row, rowCount As Integer) As List(Of Cell)
       Dim currentCount As Integer = 0
       Dim result = New List(Of Cell)
       For Each cell As Cell In row.Descendants(Of Cell)()

           Dim columnName As String = GetColumnName(cell.CellReference)

           Dim currentColumnIndex As Integer = ConvertColumnNameToNumber(columnName)

           While currentCount < currentColumnIndex

               'Here where I'm getting the error when the "cell.CellValue" is nothing'
               Dim emptycell = New Cell() With { _
               .DataType = New EnumValue(Of CellValues)(CellValues.SharedString), _
               .CellValue = New CellValue(cell.CellValue.ToString)}

               currentCount += 1
               emptycell.AppendChild(New SharedStringItem(New DocumentFormat.OpenXml.Spreadsheet.Text(Nothing)))
               result.Add(emptycell)
           End While

           result.Add(cell)
           currentCount += 1
       Next

       Return result

   End Function
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900