Monday 4 December 2017

Is it possible to force Excel recognize UTF-8 CSV files automatically?

itemprop="text">

I'm developing a part of an
application that's responsible for exporting some data into CSV files. The application
always uses UTF-8 because of its multilingual nature at all levels. But opening such CSV
files (containing e.g. diacritics, cyrillic letters, Greek letters) in Excel does not
achieve the expected results showing something like Г„/Г¤,
Г–/Г¶
. And I don't know how to force Excel understand that the open CSV
file is encoded in UTF-8. I also tried specifying UTF-8 BOM EF BB
BF
, but Excel ignores that.



Is
there any workaround?



P.S. Which tools may
potentially behave like Excel does?




/>

UPDATE



I
have to say that I've confused the community with the formulation of the question. When
I was asking this question, I asked for a way of opening a UTF-8 CSV file in Excel
without any problems for a user, in a fluent and transparent way. However, I used a
wrong formulation asking for doing it automatically. That is very
confusing and it clashes with VBA macro automation. There are two answers for this
questions that I appreciate the most: the very first answer by Alex href="https://stackoverflow.com/a/6002338/166589">https://stackoverflow.com/a/6002338/166589,
and I've accepted this answer; and the second one by Mark href="https://stackoverflow.com/a/6488070/166589">https://stackoverflow.com/a/6488070/166589
that have appeared a little later. From the usability point of view, Excel seemed to
have lack of a good user-friendly UTF-8 CSV support, so I consider
both answers are correct, and I have accepted Alex's answer first
because it really stated that Excel was not able to do that transparently. That is what
I confused with automatically here. Mark's answer promotes a more
complicated way for more advanced users to achieve the expected result. Both answers are
great, but Alex's one fits my not clearly specified question a little
better.






UPDATE
2




Five months later after the last
edit, I've noticed that Alex's answer has disappeared for some reason. I really hope it
wasn't a technical issue and I hope there is no more discussion on which answer is
greater now. So I'm accepting Mark's answer as the best one.



Answer




Alex is correct, but as you have to export to
csv, you can give the users this advice when opening the csv
files:




  1. Save the exported
    file as a csv

  2. Open
    Excel

  3. Import the data using Data-->Import External
    Data --> Import Data

  4. Select the file type of "csv" and
    browse to your file

  5. In the import wizard change the
    File_Origin to "65001 UTF" (or choose correct language character identifier)


  6. Change the Delimiter to
    comma

  7. Select where to import to and
    Finish



This way the
special characters should show correctly.



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...