Max
Can´t generate file (csv) with special chars
Hi,
i use the following code to generate a csv file. The code itself works. The problem are special chars / umlauts.
-
if i use :utf8 i get the file, but special chars like €, öäü are written like €, ü, …
-
if i don´t use :utf8 it works as long as there are no special chars in a row like €, –, … . Then it breaks with the error
erlang error: :no_translationfile = File.open!(System.tmp_dir()<>"/"<>filename, [:write, :utf8]) users = get_users(conn, params) |> Repo.all |> CSV.encode(separator: ?;) |> Enum.each(&IO.write(file, &1))
Thanks!
Most Liked
nburkley
I came across this thread when I was having similar issues displaying CSV files in Excel. After some trial-and-error with different encodings and BOM chars I found the best solution was to encode the CSV as tab-delimited UTF-16 LE.
I put together a blog post on the topic here in the hope it helps the next time someone has the same problem:
gregvaughn
I have encountered this problem at a prior job. You’ll also find different behavior for different version of Excel and whether it is the Windows or Mac version. Here’s a very good summary of the problem and possible approaches: https://stackoverflow.com/questions/6002256/is-it-possible-to-force-excel-recognize-utf-8-csv-files-automatically
If I recall, what we did was offer the user to export as either .csv or .xls. The .xls was really html table markup filled with the data, but Excel recognized that and imported it as utf8. This approach is discussed in the link above, though not the accepted answer.
gregvaughn
This may be too much of a tangent, but since this question is really about Excel and not about Elixir, I don’t feel too bad. If you know Ruby, this is the code my co-worker extracted for doing that “html table inside a .xls file” approach. Even if you don’t know Ruby, the README has more background too. GitHub - livingsocial/excelinator: convert your csv data and html tables to excel data. · GitHub
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









