Public Sub WriteTableToExcel(xlsBase As String, objTbl As B4XTable, strOutFile As String, blnShowToast As Boolean)
Try
If File.Exists(File.DirInternal, xlsBase) Then
File.Delete(File.DirInternal, xlsBase)
End If
File.Copy(File.DirAssets, xlsBase, File.DirInternal, xlsBase)
xls.Initialize("", File.Combine(File.DirInternal, xlsBase))
Dim sheet As XLSSheet = xls.getSheetAt(0)
Dim row As XSSFRow
Dim mapRow As Map
Dim intCnt As Int = 1
Dim cell As XSSFCell
Dim tblCol As B4XTableColumn
row = sheet.createRow(1)
For intCol = 0 To objTbl.Columns.Size - 1
cell = row.createCell(intCol)
tblCol = objTbl.Columns.Get(intCol)
cell.StringCellValue = tblCol.Id
Next
Sleep(0)
For intRow = 1 To objTbl.Size
row = sheet.createRow(intRow + 1)
mapRow = objTbl.GetRow(intRow)
intCnt = 0
For Each strKey As String In mapRow.Keys
cell = row.createCell(intCnt)
cell.StringCellValue = mapRow.Get(Starter.loc.Localize(strKey))
intCnt = intCnt + 1
Next
Next
If File.Exists(File.DirRootExternal,"/Documents/" & strOutFile) Then
File.Delete(File.DirRootExternal,"/Documents/" & strOutFile)
End If
xls.write2(File.DirRootExternal,"/Documents/" & strOutFile)
Sleep(0)
If blnShowToast Then
ToastMessageShow(Starter.loc.Localize("export_dgv_ok"), True)
End If
Catch
If blnShowToast Then
ToastMessageShow(LastException, True)
End If
End Try
If File.Exists(File.DirInternal, xlsBase) Then
File.Delete(File.DirInternal, xlsBase)
End If
End Sub