DB to csv export Encoding Problems

Hello guys,

it seems that i have same issue again and again with encodings ,

so i have the code :

[code] fileStream = TextOutputStream.Create(f)

        ' Put header
        fileStream.WriteLine ConvertEncoding("Nom;Prnom;Date de naissance;Profession;Taille;Poids actuel;Poids max;Poids min;IMC;Antcdents mdicaux;Antcdents chirurgicaux;Antcdents Familiaux;Antcdents antrieurs;Mdicaments;Grossesse;Parit;Tabac;Alcool;Pilule;Phlbite;FDR Divers;Allergies;Motifs de consultation;Diagnostic;Indications opratoires;Cot (0:N/C - 1:gauche - 2:droite);Rponse 1;Rponse 2;Rponse 3;Rponse 4;Rponse 5;Rponse 6;Rponse 7;Rponse 8;Rponse 9;Rponse 10;Date",Encodings.UTF8)
        fileStream.Close
      Catch e As IOException
        fileStream.Close
        MsgBox "Error Accessing file."
      End Try[/code]

The problem is that on any other app i open this csv file i see the names properly but if i open the csv in Excel the mac version i get some weird characters like this :

Nom	Prénom	Date de naissance	Profession	Taille	Poids actuel	Poids max	Poids min	IMC	Antécédents médicaux	Antécédents chirurgicaux	Antécédents Familiaux	Antécédents antérieurs	Médicaments	Grossesse	Parité	Tabac	Alcool	Pilule	Phlébite	FDR Divers	Allergies	Motifs de consultation	Diagnostic	Indications opératoires	Coté (0:N/C - 1:gauche - 2:droite)	Réponse 1	Réponse 2	Réponse 3	Réponse 4	Réponse 5	Réponse 6	Réponse 7	Réponse 8	Réponse 9	Réponse 10	Date

so what do i do wrong ? is there a way to set the encoding of the file that gets created ?

It seems that the issue shows only on Excel for mac.

If you use Xojo.IO.TextOutputStream, you have to specify the encoding as part of the Create method. Perhaps it will work better with Excel.

might have something to do with what version of excel

and a csv has no “encoding” property so I’m not sure what excel expects

Hello Paul & Norman, it seems that the issue is related to that damn Excel, in Numbers it is shown perfectly and in any other reader , the only issue i have it on Excel so i will start recommending to the customers to user Numbers instead of Excel.

As for the example from TextOutputStream , i tried this but changed for my code and it seems that i get a lot of errors :

[code]Using Xojo.Core
Using Xojo.IO

Dim f As FolderItem
f = SpecialFolder.Documents.Child(“SaveData.txt”)

Dim output As TextOutputStream
Try
output = TextOutputStream.Append(f, TextEncoding.UTF8)
output.WriteLine(“This text is appended to the end of the file.”)
output.Close
Catch e As IOException
Label1.Text = “Unable to append to file.”
End Try[/code]

i have same code but different naming and when i put the part output = TextOutputStream.Append(f, TextEncoding.UTF8 )it takes the TextEncoding but after . i have anything except encodings so it is something wrong in the IDE part,

In the same time i tried to create a new project and to put all that code in the action of a button and it seems that it is working as separate but i get some warnings like “Before 2014R3 this would have referred to the class FolderItem, but now it refers to the class xojo.IO.FolderItem” and i have all the FolderItem and SpecialFolder from examples marked with Yellow and as warnings.

So either the ide has something or there is something fishy on my project, i will have to look in the morning.

Well it seems that the issue is indeed the version of Excel and a workaround for that would be to use iconv something like this :

iconv -f UTF-8 -t WINDOWS-1252 test.csv > test_utf8.csv

and it will work ok afterwords so maybe i will use a shell command to reconvert the windows encoding into UTF8.

Thanks.

You can use TextEncoding.WIndows1252 to save directly to that encoding.

You may be getting errors in your code because you cannot use a Classic FolderItem with the new framework TextOutputStream class. You can convert like this though:

Dim f As FolderItem = GetOpenFolderItem("") Dim saveFile As New Xojo.IO.FolderItem(f.NativePath.ToText) // saveFile now works with Xojo.IO.TextOutputStream

[quote=209545:@Paul Lefebvre]You can use TextEncoding.WIndows1252 to save directly to that encoding.

You may be getting errors in your code because you cannot use a Classic FolderItem with the new framework TextOutputStream class. You can convert like this though:

Dim f As FolderItem = GetOpenFolderItem("") Dim saveFile As New Xojo.IO.FolderItem(f.NativePath.ToText) // saveFile now works with Xojo.IO.TextOutputStream [/quote]

Good morning Paul,

May i ask what is the purpose of the new naming convention ? is it related to the new El Capitan or just to go seamlessly with IOS ? Initially i choose XOJO due to simplicity and clean design and to avoid that winnie code that comes from Xcode or even swift but it seems that those name spaces start to come here as well, and from my understanding, by using Using Xojo.IO does not that function offers you the functions from that class ? so that it can be used as FolderItem instead of XOJO.IO.FolderItem ? if not , then why do we have to use that using ? and not directly use XOJO.IO.FolderItem ? maybe i got it wrong but this was my understanding when using Using, it should be same like any other language, it makes available all the methods and properties from that class .

One question that might not get a answer for it but i will try, it the new framework will replace the old in the near future ? as i have a lot of projects with thousands of lines of code and to adapt those to the new framework will take a while, if i can still use it like that i will be more than happy, but eventually the time will come when i will have to do the conversion.

I will try the encoding as you said and see what i get.

Thanks.

Ciao Aurelian, come stai ?

it may not be related, but I recently had a trouble with SQLite (in fact I was doing something wrong, it was not SQLite):

The text taken from the ListBox where I loaded from the db, pasted in TextEdit had the correct encoding, but displayed in the ListBox… same looking as you say.

After some days, it happens that I’ve done a bad Copy / Paste in the create table: I created a Text Column as… INTEGER instead of TEXT. But I loaded it as TEXT…

I was starting to pull hair from my head when I saw that.

[quote=209684:@Emile Schwarz]Ciao Aurelian, come stai ?

it may not be related, but I recently had a trouble with SQLite (in fact I was doing something wrong, it was not SQLite):

The text taken from the ListBox where I loaded from the db, pasted in TextEdit had the correct encoding, but displayed in the ListBox… same looking as you say.

After some days, it happens that I’ve done a bad Copy / Paste in the create table: I created a Text Column as… INTEGER instead of TEXT. But I loaded it as TEXT…

I was starting to pull hair from my head when I saw that.[/quote]
Hello Emile, nothing to do with that, ghe issue is from encodings, it seems that on last update on office for mac the guys from microsoft as usual they forgot to put mac encodings there and it gets encoded with some windows rncoding, the best fix is to ise numbers, it works perfect , thanks for your advice .

Take care.

Mobile typing sory for the mistakes