Posted 8 September 2017, 3:03 pm EST
I am trying to obtain information about a cell in an Excel spreadsheet loaded with the OpenExcel method.
It appears that for Excel files all cell types will be returned by the GetCellType method as a GeneralCellType. I would like to examine the FormatString, DateTimeFormat and NumberFormat properties of the GeneralCellType object to determine the possible cell types.
If the contents of my spread control holds an Excel file, I type cast the return of GetCellType into a GeneralCellType and examine the FormatString, DateTimeFormat and NumberFormat properties to set the initial control values for a custom dialog similar to Excel's "Format Cells" dialog.
I was trying a GetParseFormat to see if any additional information (or more specific information) could be obtained. My call to GetParseFormat succeeds (does not throw any IndexOutOfRange exceptions) - but also returns nothing (or Null) for the two ByRef parameters. My code to call GetParseInfo is below. Is this syntax correct?
Dim _numberFormatInfo As System.Globalization.NumberFormatInfo
Dim _formatString As String = String.Empty
_currentCellType = ActiveSheet.GetCellType(_row, _col)
If (_isExcelFile = True) Then
' All Excel cell types are returned as General. - Cell type info is found in DateAndTimeFormat and NumberFormat...
Dim _generalCellType As CellType.GeneralCellType = CType(_currentCellType, CellType.GeneralCellType)
If(_generalCellType.NumberFormat IsNot Nothing) Then
_generalCellType.GetParseFormat(_row, _col, _formatString, _numberFormatInfo)
Catch ex As IndexOutOfRangeException