I use this code to export B4Xtable contents to CSV file, then I use FileProvider to open it by Excel or Google Sheets, they do open the file OK, but unfortunately both of them dont show Arabic letters correctly.
I have to open saved CSV by notepad then save it in UTF8 and reopen it again by Excel or Google Sheets, is there any method to save the CSV file in UTF8?
thanks
I have to open saved CSV by notepad then save it in UTF8 and reopen it again by Excel or Google Sheets, is there any method to save the CSV file in UTF8?
thanks
B4X:
Dim st As clsSysTools
st.Initialize
Wait For (CallSub3(st, "ExportTableToCSV",Table,Filename)) Complete (Exported As Boolean)
If Exported Then
ToastMessageShow("Data Exported OK",False)
Dim in As Intent
in.Initialize(in.ACTION_VIEW, "")
Starter.Provider.SetFileUriAsIntentData(in, Filename)
in.SetType("text/csv")
StartActivity(in)
Return True
B4X:
Public Sub ExportTableToCSV(Table As B4XTable,ExportFileName As String) As ResumableSub
Try
Dim data As List
data.Initialize
Dim CSVHeaders As List
CSVHeaders.Initialize
'Dim rs As ResultSet = Table.sql1.ExecQuery("SELECT * FROM data")
Dim o() As Object = Table.BuildQuery(False) 'True to include the page LIMIT in the query.
Dim rs As ResultSet = Table.sql1.ExecQuery2(o(0), o(1))
Do While rs.NextRow
Dim row(Table.Columns.Size) As String
For i = 0 To Table.Columns.Size - 1
Dim c As B4XTableColumn = Table.Columns.Get(i)
row(i) = rs.GetString(c.SQLID)
Next
data.Add(row)
Loop
For i = 0 To Table.Columns.Size - 1
Dim c As B4XTableColumn = Table.Columns.Get(i)
CSVHeaders.Add(c.Title)
Next
rs.Close
Dim su As StringUtils
Dim StorageDir As String = Starter.Provider.SharedFolder
su.SaveCSV2(StorageDir, ExportFileName, Chr(9), data,CSVHeaders)
Return True
Catch
Log(LastException)
Return False
End Try
End Sub