Excel not recognize automatically generated CSV files using utf-8 encoding

I generate utf-8 encoding output in Julia by using DelimitedFiles package. I would like students to be able to read the generated files automatically in EXCEL by using utf-8 encoding without going into the pain in Excel to read the data tab (1) Get Data from File, (2) change encodement, (3) save file etc…

Therefore is there a way to tell EXCEL that the generated file is a utf-8 encoding and not a Western European encoding?

Many thanks for any help you may provide,

UTF-8 is not really used in the Windows universe. You my try to encode your data while writing to UTF-16LE and see whether Excel reads that without trouble. Additionally you may have to insert the BOM sequence at the very beginning of the file.

Thanks Wolfgang,

So how to write a UTF-16LE output in Julia?

How to insert the BOM sequence at the very beginning of the file?

Thanks for all your help,
Joseph

Did you try googling “utf8 excel csv?” You would have found this:

1 Like

(UTF-8 is the most common encoding on the web, so plenty of Windows software can handle it. You just need to tell it the encoding.)

Hi Steven,

Thanks for your answer. We know how to read UTF-8 encoding in Excel but it is a real pain. I was just wandering if there is a way to tell EXCEL before opening the file that the file is in UTF-8 encoding?

Thanks,
Joseph

According to this post, writing a BOM at the beginning of the file will cause Excel 2007 or later to automatically treat a CSV file as UTF8:

https://stackoverflow.com/questions/155097/microsoft-excel-mangles-diacritics-in-csv-files

In Julia, do write(file, [0xef,0xbb,0xbf]) at the beginning of the file, before you write the CSV data.

2 Likes

Maybe just creat .xlsx with XLSX.jl would be easier soultion?

Thanks Steven for solving the problem. Your solution works remarkably well and when I open now .csv in EXCEL one can see the greek symbols in the header :grinning: Below is an example how I use it.

		import DelimitedFiles
			open(path.Table_θΨK, "w") do io
				DelimitedFiles.write(io, [0xef,0xbb,0xbf]) 
				DelimitedFiles.writedlm(io,[FieldName_String] , ",",) # Header
				DelimitedFiles.writedlm(io, [Id_Select Matrix], ",")
			end

1 Like

Hi Yong thanks for providing an alternative solution.

I believe that writing in .xlsx is indeed an alternative solution for small files but for larger files I believe that writing in .csv is faster and takes less memory, STEVENGJ :point_up_2: provides a good solution :smile:.