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

**URL:** <https://discourse.julialang.org/t/excel-not-recognize-automatically-generated-csv-files-using-utf-8-encoding/35258>\
**Category:** Data\
**Tags:** question, data, data\_structures\
**Created:** [February 27, 2020, 8:51pm UTC](https://discourse.julialang.org/t/excel-not-recognize-automatically-generated-csv-files-using-utf-8-encoding/35258 "2020-02-27T20:51:54Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)\
**Post date:** [February 27, 2020, 8:51pm UTC](https://discourse.julialang.org/t/excel-not-recognize-automatically-generated-csv-files-using-utf-8-encoding/35258/1 "2020-02-27T20:51:54Z")

</div>

> 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,

---

<div class="post-metadata">

**Author:** ![wolfgang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wolfgang/32/13053_2.png) [@wolfgang](https://discourse.julialang.org/u/wolfgang)\
**Post date:** [February 27, 2020, 9:26pm UTC](https://discourse.julialang.org/t/excel-not-recognize-automatically-generated-csv-files-using-utf-8-encoding/35258/2 "2020-02-27T21:26:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)\
**Post date:** [February 27, 2020, 9:34pm UTC](https://discourse.julialang.org/t/excel-not-recognize-automatically-generated-csv-files-using-utf-8-encoding/35258/3 "2020-02-27T21:34:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 27, 2020, 11:10pm UTC](https://discourse.julialang.org/t/excel-not-recognize-automatically-generated-csv-files-using-utf-8-encoding/35258/4 "2020-02-27T23:10:37Z")

</div>

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

> **[How to import a .csv file that uses UTF-8 character encoding](https://www.ias.edu/itg/content/how-import-csv-file-uses-utf-8-character-encoding-0)**
>
> Follow the steps outlined below to use Microsoft Excel 2007 to open a .csv file that uses UTF-8 character encoding.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 27, 2020, 11:13pm UTC](https://discourse.julialang.org/t/excel-not-recognize-automatically-generated-csv-files-using-utf-8-encoding/35258/5 "2020-02-27T23:13:02Z")

</div>

(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.)

---

<div class="post-metadata">

**Author:** ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)\
**Post date:** [February 27, 2020, 11:27pm UTC](https://discourse.julialang.org/t/excel-not-recognize-automatically-generated-csv-files-using-utf-8-encoding/35258/6 "2020-02-27T23:27:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 28, 2020, 1:14am UTC](https://discourse.julialang.org/t/excel-not-recognize-automatically-generated-csv-files-using-utf-8-encoding/35258/7 "2020-02-28T01:14:42Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![YongHee-Kim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yonghee-kim/32/5965_2.png) [@YongHee-Kim](https://discourse.julialang.org/u/YongHee-Kim)\
**Post date:** [February 28, 2020, 2:21am UTC](https://discourse.julialang.org/t/excel-not-recognize-automatically-generated-csv-files-using-utf-8-encoding/35258/8 "2020-02-28T02:21:01Z")

</div>

Maybe just creat .xlsx with [XLSX.jl](https://felipenoris.github.io/XLSX.jl/dev/tutorial/#Writing-Excel-Files-1) would be easier soultion?

---

<div class="post-metadata">

**Author:** ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)\
**Post date:** [March 1, 2020, 9:42pm UTC](https://discourse.julialang.org/t/excel-not-recognize-automatically-generated-csv-files-using-utf-8-encoding/35258/9 "2020-03-01T21:42:44Z")

</div>

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 😀 Below is an example how I use it.

```julia
		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

```

---

<div class="post-metadata">

**Author:** ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)\
**Post date:** [March 1, 2020, 9:46pm UTC](https://discourse.julialang.org/t/excel-not-recognize-automatically-generated-csv-files-using-utf-8-encoding/35258/10 "2020-03-01T21:46:51Z")

</div>

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 👆 provides a good solution 😄.
