Change default encoding of Excel to UTF-8?

26

6

I am using a variety of tools to regularly prepare data for the web. One stage requires me to open a CSV in Excel, make changes and save the file.

Is there a way to force Excel to accept UTF-8 encoding, and to save its files with that encoding?

Dizzley

Posted 2015-05-06T10:12:17.713

Reputation: 823

1To clarify, I would like to change a setting so that Excel assumes an input file is UTF-8 by default. As mentioned below, LibreOffice/OpenOffice does this. – Dizzley – 2015-10-30T12:02:17.747

If you don't actually have Unicode characters to deal with, I'd consider using a middleware to convert all CSVs to ASCII and then open in Excel. – Vassile – 2016-02-28T07:54:12.847

1

Related question here but not exactly the same.

– hhh – 2017-01-27T08:09:50.747

Answers

15

I answered a similar question at Default character encoding for Excel Text Wizard?.

I found my answer at Changing default text import origin type in Excel.

  1. In the registry editor, go to HKEY_CURRENT_USER>Software>Microsoft>Office>[Excel version here—likely the highest number in this folder]>Excel>Options
  2. right-click on the right side and go to New > DWORD
  3. name the item DefaultCPG, and save
  4. right-click on DefaultCPG and choose Modify
  5. set the base to decimal
  6. enter the code that’s shown in the Excel wizard (for UTF-8, it’s 65001)
  7. click OK.

Like Vasille says in the comment to this question, if your file is not actually in UTF-8 format, you may technically want to convert the characters within the file to the encoding you want before opening in Excel. For my purposes, though, UTF-8 does a good enough job of displaying non-corrupted characters.

Robert H.

Posted 2015-05-06T10:12:17.713

Reputation: 174

3Are there any reasons not to do this? Why is this not the default behavior of Excel?


My team often deals with datasets containing foreign characters, and I'm wondering if there is any reason to not perform this action on each of our machines. – user1318135 – 2017-08-23T20:43:27.197

3This unfortunately did not work on my machine. Files still open with default encoding (Win 7, Office 2016). – user1318135 – 2017-08-23T20:46:24.033

8Doesn't work on mine also, Win 10 Office 2016 – Phuah Yee Keat – 2018-06-21T03:46:11.623

2No dice. Excel behaves as stupidly as ever. One would expect an obvious feature like this to be accessible via a user preference in software as mature as Excel. – Aaron Bramson – 2018-09-18T09:22:26.290

4

One easy way to change excel ANSI encoding to UTF-8 is the open the .csv file in notepad then select File > Save As. Now at the bottom you will see encoding it set to ANSI change it to UTF-8 and save the file as new file and then your done.

Moudiz

Posted 2015-05-06T10:12:17.713

Reputation: 647

I will experiment with this. One problem I have is opening files consistently in the correct encoding so I do not get data in two encodings in a single results file. Then it becomes hard to fix. I really wish Excel allowed me a better way to choose input file encoding. – Dizzley – 2015-05-06T14:59:33.837

3

It seems that Byte Order Mark is required by Microsoft Office software.

  1. Using Notepad++, convert the CSV using menu: Encoding -> Convert to UTF8-BOM.

  2. Using the sed Unix utility, available in cmder or Git for Windows. See Adding BOM to UTF-8 files.

    sed -i '1s/^/\xef\xbb\xbf/' file.csv
    

  • Tested with Excel 2016
  • This is what avwtp meant in their answer.

Cristian

Posted 2015-05-06T10:12:17.713

Reputation: 31

2

You need to use the File > Import option and start with blank document and specify UTF-8

enter image description here

but this is far from optimal to make this a default setting for all files, anyway it is unnecessary to rotate the files around Google Drive or LibreOffice. The defaults are just badly chosen and the disability to change that is irritating.

Related

  1. How to set character encoding when opening Excel but does not find the option to change the defaults such that all files are automatically opened with UTF-8 instead of Macintosh format in OSX

  2. How to change default file option to UTF-8 away from Macintosh file option in Apple.SE.

hhh

Posted 2015-05-06T10:12:17.713

Reputation: 673

0

Assuming you have a unix shell available (Cygwin), I append to the front of the csv file a little 3 char unicode ID (UTF-8) and then it reads fine into Excel and more importantly it is properly processed as input using VB Excel automation.

UTF-8.txt

EFBBBF << hex edit into a 3 char file.

cat UTF-8.txt file-to-use.csv > new_file.csv

avwtp

Posted 2015-05-06T10:12:17.713

Reputation: 1

1(1) Can you describe how/why this works? (2) Can you describe exactly how to create this UTF-8.txt file? – Scott – 2019-04-30T00:41:55.387

I suggest using a hex editor and typing in the 3 character sequence. Why it works, no idea. I figured out this solution by taking an existing UTF-8 csv file, renaming it to txt, importing it into Excel (like suggested in other threads), saving it as CSV with the Unicode plugin (other thread) and then doing a binary diff of the two files. The only difference was the 3 character starting sequence. – avwtp – 2019-04-30T19:08:13.507

See this thread why it works [link] (https://stackoverflow.com/questions/6002256/is-it-possible-to-force-excel-recognize-utf-8-csv-files-automatically)

– avwtp – 2019-04-30T19:22:06.773

0

I solved similar problem before. Unsuccessfully, but you can use LibreOffice, which is UTF-8 in default.

Lluser

Posted 2015-05-06T10:12:17.713

Reputation: 176

LibreOffice is very handy for this. However, sometimes I have VBA macros to run. Thanks Lluser – Dizzley – 2015-05-06T14:56:56.020

0

There's an Excel addin available here to work with Unicode CSV files that should help you.

Here's the developer Jaimon Mathew's note:

Excel treats .csv files as text files and will replace all Unicode characters with “?” when saved normally. If you want to preserve the Unicode characters, you would need to save the file as “Unicode text (*.txt)”, which is a Tab delimited file. Since I couldn’t find any existing solution to preserve Unicode characters in CSV format, I thought I’ll give it a go in creating an Excel Addin to do just that.

1

Karan

Posted 2015-05-06T10:12:17.713

Reputation: 51 857

0

It's not the best solution, but it's an option: upload your Excel file to Google drive, open it with Google Tabs and download as a csv file. It worked for me.

Viktor

Posted 2015-05-06T10:12:17.713

Reputation: 1

5This does not answer the question how to change the encoding of Excel document. – Ramhound – 2015-10-02T12:01:16.597

Of course, when you open the CSV in Excel you lose the cell formatting so some numeric ID strings get converted to integers. – Dizzley – 2015-10-30T12:00:49.700