Spanish [SOLUCIONADO] PROBLEMAS AL EXPORTAR A UN CSV CON ACENTOS

Anton Solans Argemí

Active Member
Licensed User
Al hacer una exportación de una tabla a un csv los datos con acentos no me los exporta correctamente.

B4X:
ListCSV=utils.ExecuteMemoryTable(sql1,lssql,Null,0)
sd.SaveCSV(gsdircsv,"prueba.csv",";",ListCSV)
 

josejad

Expert
Licensed User
Longtime User
El problema lo tienes al abrirlo con Excel o con cualquier editor? Se ven correctamente en Notepad++?
 

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.
 

Anton Solans Argemí

Active Member
Licensed User
José, el problema lo tengo en Excel y en Word Pad, con el Bloc de Notas me lo hace bien.

Probaré lo que me comentas Klaus.

Muchas gracias a los dos.
 

Anton Solans Argemí

Active Member
Licensed User
Klaus, tu solución me ha funcionado.

Adjunto código utilizado:

B4X:
    Dim sd As StringUtils
    Dim ListCSV As List
    Dim tr As TextReader
    Dim tw    As TextWriter
    Dim s As String
     
    ....
     
    ListCSV=utils.ExecuteMemoryTable(sql1,lssql,Null,0)
    sd.SaveCSV(gsdircsv,"prueba.csv",";",ListCSV)
       
    tr.Initialize(File.OpenInput(gsdircsv, "prueba.csv"))
    S = tr.ReadAll
    tr.Close
       
    tw.Initialize2(File.OpenOutput(gsdircsv,"prueba.csv",False),"Windows-1252")
    tw.write(s)
    tw.Close

   ....

Muchas gracias por vuestra ayuda.
 
Top