Sub GetFormattedCellValue(workbook As XLWorkbookWriter, cell As PoiCell)
Dim props As Map
props.Initialize
Dim val As String = cell.Value.As(String)
XLgetCellStyleInfo(workbook, props, cell.CellStyle)
Select Case props.GetDefault("setDataFormat", 0).As(Int) ' See https://poi.apache.org/apidocs/dev/org/apache/poi/ss/usermodel/BuiltinFormats.html
Case 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 37, 38, 39, 40, 41, 42, 43, 44
' Numbers with or without decimals
Case 11, 48
' Float
Case 14, 15, 16, 17, 169 ' 169: not documented on the aforementioned page, found it experimentally
' Date
Log("Date: " & DateToDDMMYYYYwithSlashes(val.As(Long)))
Case 18, 19, 20, 21, 45, 46, 47
' Time
Case 22
' Datetime
Log("Date: " & DateToDDMMYYYYwithSlashes(val.As(Long)))
Case Else
' Text
End Select
xui.MsgboxAsync("Hello World!", "B4X")
End Sub
'Call as:
'Dim props as Map
'Dim Cell As PoiCell
'XLgetCellStyleInfo(props, Cell.CellStyle)
Public Sub XLgetCellStyleInfo(workBook As XLWorkbookWriter, props As Map, CellStyle As PoiCellStyle)
' Code from XLUtils.b4xlib/XLSheetWriter.bas - see https://www.b4x.com/android/forum/threads/xlutils-jpoi-5-read-styles.140554
Dim jStyle As JavaObject = CellStyle
For Each methods As List In workBook.InternalAllSimpleMethods
For Each method As String In methods
props.Put(method, jStyle.RunMethod("g" & method.SubString(1), Null))
Next
Next
props.Put("setFont", jStyle.RunMethod("getFontIndex", Null))
For Each method As String In workBook.InternalStyleStrings
props.Put(method, jStyle.RunMethodJO("g" & method.SubString(1), Null).RunMethod("toString", Null))
Next
End Sub
Public Sub DateToDDMMYYYYwithSlashes(dateIn As Long) As String
Dim OrigFormat As String = DateTime.DateFormat 'save orig date format
DateTime.DateFormat = "dd/MM/yyyy"
Dim YYYYMMDDout As String = DateTime.Date(dateIn)
DateTime.DateFormat = OrigFormat 'return to orig date format
Return YYYYMMDDout
End Sub