Greetings community,
Below is the code I use to export my data from my B4xTable to csv and it works for me. But now, i want to be able to export specific columns. Lets say, i want to export all the columns ["USERNAME", "ID","FULLNAME","DATE OF BIRTH","CONTACT","EMAIL","USERTYPE","INSTITUTION","LASTLOGIN"] except that of the ["ID","LASTLOGIN","DATE OF BIRTH"]. How do i do that?
Below is the code I use to export my data from my B4xTable to csv and it works for me. But now, i want to be able to export specific columns. Lets say, i want to export all the columns ["USERNAME", "ID","FULLNAME","DATE OF BIRTH","CONTACT","EMAIL","USERTYPE","INSTITUTION","LASTLOGIN"] except that of the ["ID","LASTLOGIN","DATE OF BIRTH"]. How do i do that?
B4X:
Private const CSVFileName As String ="userDetails.csv"
Dim data As List
data.Initialize
Dim headers As List
headers.Initialize
headers.AddAll(Array As String("USERNAME", "ID","FULLNAME","DATE OF BIRTH","CONTACT","EMAIL","USERTYPE","INSTITUTION","LASTLOGIN"))
Dim rs As ResultSet = B4XTable1.sql1.ExecQuery($"SELECT * FROM data"$)
If rs.RowCount>0 Then
Dim sf As Object = xui.Msgbox2Async($"Do you want to export this table?"$, "Export", "Yes", "", "No", Null)
Wait For (sf) Msgbox_Result (Result As Int)
If Result = xui.DialogResponse_Positive Then
Do While rs.NextRow
Dim row(B4XTable1.Columns.Size) As String
For i = 0 To B4XTable1.Columns.Size - 1
Dim c As B4XTableColumn = B4XTable1.Columns.Get(i)
row(i) = rs.GetString(c.SQLID)
Next
data.Add(row)
Loop
rs.Close
Dim su As StringUtils
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For activity_permissionresult(permission As String,res As Boolean)
If res=True Then
su.SaveCSV2(File.Combine(File.DirRootExternal,"Download"), CSVFileName, ",", data, headers)
Dim Answ As Object
Dim Txt As String
Txt = $"List successfully exported."$
Answ = Msgbox2Async(Txt, "Export", "Yes", "", "No", Null,False)
Wait For (Answ) msgbox_result(resul As Int)
If resul = DialogResponse.POSITIVE Then
ToastMessageShow($"You can find the exported list in your downloads folder as "${CSVFileName}""$,True)
Else
ToastMessageShow($"You can find the exported list in your downloads folder as "${CSVFileName}""$,True)
Return
End If
Else
ToastMessageShow("Storage permission not granted",True)
Return
End If
End If
Else
MsgboxAsync("Sorry!! You cannot export an empty table.","Export")
ToastMessageShow("There is no data to export.", True)
End If