Public Sub ExportTableToExcel(Table As B4XTable, FileName As String)
Log("Exporting table.")
Dim Download_Path As String = File.DirRootExternal & "/Download"
Log($"File Dir: ${Download_Path}/${FileName}"$)
Dim newWorkbook As WritableWorkbook
newWorkbook.Initialize(Download_Path, $"${FileName}"$)
Dim sheet1 As WritableSheet
sheet1 = newWorkbook.AddSheet(FileName, 0)
Dim iColumn As Int = 0
For Each Column As B4XTableColumn In Table.Columns
Dim cell As WritableCell
cell.InitializeText(iColumn, 0, Column.Title)
sheet1.AddCell(cell)
iColumn = iColumn + 1
Next
For i = 1 To Table.Size
Dim cInt As Int = 0
For Each Column As B4XTableColumn In Table.Columns
Dim Row As Object = Table.GetRow(i).Get(Column.Title)
Dim cell As WritableCell
cell.InitializeText(cInt, i, Row)
sheet1.AddCell(cell)
cInt = cInt + 1
Next
Next
'Must call write and close to save the data.
newWorkbook.Write
newWorkbook.Close
xui.MsgboxAsync($"File Dir: ${Main.Path}/${FileName}"$,"Table Exported")
Log("Export sucessfull!...")
End Sub