Sub ResultSet2XL(oRS As ResultSet, tFF As tFolderAndFile, strSheetName As String, arrDataTypes() As String)
Dim r As Int
Dim c As Int
Dim n As Int
Dim iCols As Int = oRS.ColumnCount
Dim oWWB As WritableWorkbook
Dim oWS As WritableSheet
Dim bCellFormatting As Boolean = IsArray(arrDataTypes)
General.StartSW(3)
oWWB.Initialize(tFF.strFolder, tFF.strFile)
oWS = oWWB.AddSheet(strSheetName, 0)
oRS.Position = 0
For c = 0 To iCols - 1
Dim oCell As WritableCell
oCell.InitializeText(c, 0, oRS.GetColumnName(c))
oWS.AddCell(oCell)
Next
oRS.Position = -1
If bCellFormatting Then
Do While oRS.NextRow
r = r + 1
For c = 0 To iCols - 1
'Log("arrDataTypes(" & c & "): " & arrDataTypes(c))
Dim oCell As WritableCell
Select Case arrDataTypes(c)
Case "T"
oCell.InitializeText(c, r, oRS.GetString2(c))
Case "I", "XD"
oCell.InitializeNumber(c, r, oRS.GetInt2(c))
Case "R"
oCell.InitializeNumber(c, r, oRS.GetDouble2(c))
Case Else
oCell.InitializeText(c, r, oRS.GetString2(c))
End Select
oWS.AddCell(oCell)
Next
If r Mod 65530 = 0 Then 'in .xls sheet max rows = 65536
n = n + 1
r = 0
Dim oWS As WritableSheet = oWWB.AddSheet(strSheetName & "_" & (n + 1), n)
For c = 0 To iCols - 1
Dim oCell As WritableCell
oCell.InitializeText(c, r, oRS.GetColumnName(c))
oWS.AddCell(oCell)
Next
End If
Loop
Else
Do While oRS.NextRow
r = r + 1
For c = 0 To iCols - 1
Dim oCell As WritableCell
oCell.InitializeText(c, r, oRS.GetString2(c))
oWS.AddCell(oCell)
Next
If r Mod 65530 = 0 Then 'in .xls sheet max rows = 65536
n = n + 1
r = 0
Dim oWS As WritableSheet = oWWB.AddSheet(strSheetName & "_" & (n + 1), n)
For c = 0 To iCols - 1
Dim oCell As WritableCell
oCell.InitializeText(c, r, oRS.GetColumnName(c))
oWS.AddCell(oCell)
Next
End If
Loop
End If
oWWB.Write
oWWB.Close
Dim rs As ResumableSub = Dialog.Show(Activity, Array As Object("OK"), _
"SQL to .xls", "", _
"SQL result written to:" & CRLF & CRLF & tFF.strFolder & tFF.strFile & _
CRLF & CRLF & "Number of rows: " & oRS.RowCount & _
CRLF & CRLF & "Sheet cell formatting: " & bCellFormatting & _
CRLF & CRLF & "Time taken: " & General.FormatMilliSecs(General.StopSW(3)) , _
-1, False, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Null, False, arrS, 1)
Wait For (rs) Complete (strResult As String)
End Sub