Android Question Export to CSV can't be read.

makis_best

Well-Known Member
Licensed User
Longtime User
I export some info from sqlite database to csv file.
The data in database are in Greek.

The code I use to save data is
B4X:
Public Sub SaveTableToCSV(Dir As String, Filename As String)
    Dim headers(mNumberOfColumns) As String
    For i = 0 To headers.Length - 1
        Dim L As Label
        L = Header.GetView(i)
        headers(i) = L.Text
    Next
    StringUtils1.SaveCSV2(Dir, Filename, ",", Data, headers)
End Sub

But when I open the CSV file I cant read anything and the excel show something like.

Ξ—ΞΌΞ½Ξ―Ξ±,Παραστατικό,Αιτιολογία,ΧρΞωση,Πίστωση,Υπόλοιπο
,,Εκ μεταφοράς (Ξως 30/06/2019),0.00 €,0.00 €,782.22 €
,ΑΕΠ-Χ-03664,Απόδειξη είσπραξης ΑΠΔ Δ Νο 9886,0.00 €,758.75 €,-758.75 €
15/07/2019,ΤΔΑ-11537,Τιμολόγιο Πώλησης - Δελτίο αποστολής ,368.99 €,0.00 €,-389.76 €
07/08/2019,ΤΔΑ-11956,Τιμολόγιο Πώλησης - Δελτίο αποστολής ,289.35 €,0.00 €,-100.41 €
12/08/2019,ΑΕΠ-Χ-03800,Απόδειξη είσπραξης ΑΠΔ Ζ Νο 9419,0.00 €,658.34 €,-758.75 €
24/09/2019,ΤΔΑ-12613,Τιμολόγιο Πώλησης - Δελτίο αποστολής ,409.66 €,0.00 €,-349.09 €
,,Σύνολα,1068.00 €,1417.09 €,-349.09 €

How I can fix it?
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I export some info from sqlite database to csv file.
The data in database are in Greek.

The code I use to save data is
B4X:
Public Sub SaveTableToCSV(Dir As String, Filename As String)
    Dim headers(mNumberOfColumns) As String
    For i = 0 To headers.Length - 1
        Dim L As Label
        L = Header.GetView(i)
        headers(i) = L.Text
    Next
    StringUtils1.SaveCSV2(Dir, Filename, ",", Data, headers)
End Sub

But when I open the CSV file I cant read anything and the excel show something like.



How I can fix it?

You don't show how you got your data and I think headers needs to be a list, not an array.

RBS
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
I read data from a table

B4X:
Sub Globals
    Private Kartela_Table As Table
End Sub

Sub SendBtn_Click
    Dim Message As Email
    Message.To.Add(EmailEditText.Text)
    Message.Subject = "ΚΑΡΤΕΛΑ ΠΕΛΑΤΗ: " & NameEditText.Text
    Kartela_Table.SaveTableToCSV(Starter.SafeFolder, "kartela - " & NameEditText.Text & ".csv")
    Message.Attachments.Add(File.Combine(Starter.SafeFolder, "kartela - " & NameEditText.Text & ".csv"))
    StartActivity(Message.GetIntent)
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

klaus

Expert
Licensed User
Longtime User
The problem is Excel not B4A.
If you want to read it with Excel you need to change the encoding.
As a workaround, after having saved the file with SaveTableToCSV, you can:
Read the file back with TextReader.ReadAll and save it back with TextWriter.Initialize2 and TextWriter.Write where you can set the encoding you need.
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
OK... I make the chances with TextWriter.Initialize2 but now StartActivity(Message.GetIntent)
not working properly... It doesn't show the list of available applications to choose from but
start the Exchange server settings
 
Upvote 0
Top