Sub topic 7
Character encoding and spreadsheet locale
This chapter covers two settings that decide how Google Sheets reads the raw bytes and text of a delimited file: the character encoding and the spreadsheet locale. It assumes you can use File > Import, know what a CSV file is, and have read the earlier chapters on separator type and type conversion. Both settings cause problems that look like bad data but are really bad interpretation.
Two different questions
A delimited file is a stream of bytes. Google Sheets must answer two separate questions to turn it into cells.
- Encoding: which characters do these bytes stand for? This decides whether
éappears correctly or asé. - Locale: how should text such as
1.234,56or03/04/2026be interpreted as a number or date? This decides whether a value becomes a number, a date, or stays text, and which date it becomes.
The two problems are easy to confuse. Garbled characters point to encoding. Wrong numbers and swapped day and month point to locale. The diagram shows where each one acts during an import.
Character encoding
An encoding is a rule that maps bytes to characters. In plain English text, most encodings agree, because the letters A to Z use the same bytes almost everywhere. They disagree on accented letters, symbols, and non-Latin scripts.
Common encodings you will meet
| Encoding | Typical source | Notes |
|---|---|---|
| UTF-8 | Most modern tools, Linux, macOS, web exports | Covers all languages. The safe default. |
| UTF-8 with BOM | Excel "CSV UTF-8" export | Starts with three marker bytes. Sheets handles it. |
| Windows-1252 | Older Windows software, Excel "CSV (Comma delimited)" in Western locales | Western European languages only. |
| ISO-8859-1 | Older Unix tools and databases | Almost identical to Windows-1252. |
| UTF-16 | Some Excel "Unicode Text" exports | Two bytes per character. Usually tab-separated. |
What Sheets does
The File > Import dialog has no encoding menu. Google Sheets detects the encoding automatically. UTF-8 files import cleanly. Files in older single-byte encodings often import correctly too, but detection is a guess. A short file with only a few accented characters gives the detector little evidence, so it can guess wrong.
Recognizing an encoding failure
Encoding failures leave a recognizable pattern, called mojibake. The same characters corrupt the same way every time.
| You see | The file contains | What happened |
|---|---|---|
| `é` | `é` | UTF-8 bytes were read as Windows-1252 |
| `ü` | `ü` | UTF-8 bytes were read as Windows-1252 |
| `’` | `’` (curly apostrophe) | UTF-8 bytes were read as Windows-1252 |
| `�` | any non-ASCII character | Bytes were invalid in the encoding used |
| `ÿþ` at the start | A UTF-16 file | The file was read as a single-byte encoding |
If you see é-style text, the file is UTF-8 but was read as a single-byte encoding. If you see � (the replacement character), information was already lost, and re-importing the same file will not bring it back.
Fixing encoding problems
Fix the file, not the sheet, whenever you can.
- Re-export from the source as UTF-8. In Excel, choose CSV UTF-8 (Comma delimited) under Save As.
- If you only have the file, open it in a text editor that shows and converts encodings, then save it as UTF-8.
- Import the new file.
If the file is already in Drive, an Apps Script import lets you name the encoding yourself. The getDataAsString method takes a charset argument:
function importCsvWithEncoding() {
const fileId = 'YOUR_FILE_ID';
// Use 'windows-1252' (or 'ISO-8859-1') for older Western European files.
const csvText = DriveApp.getFileById(fileId)
.getBlob()
.getDataAsString('windows-1252');
const rows = Utilities.parseCsv(csvText);
const sheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet('Imported');
sheet.getRange(1, 1, rows.length, rows[0].length).setValues(rows);
}This is the same approach as the basic Drive import. The only change is the charset name passed to getDataAsString. Pass the wrong name and you get mojibake again, so match it to what the file's producer used.
Spreadsheet locale
A locale is a set of regional conventions. In Google Sheets the locale belongs to the spreadsheet, not to your account and not to the file you import. Set it under File > Settings > General > Locale. The same setting also holds the time zone.
The locale controls:
- The decimal separator (
.or,) and the thousands separator. - The default date order (month/day/year, day/month/year, or year/month/day).
- The default currency format.
- The argument separator in formulas on some locales (
,or;).
Why the locale matters for import
When the Convert text to numbers, dates, and formulas option is on, Sheets reads each cell's text using the locale of the destination spreadsheet. The file has no say. A file produced in Germany and imported into a spreadsheet set to United States behaves very differently from the same file imported into a spreadsheet set to Germany.
| Text in the file | Locale: United States | Locale: Germany |
|---|---|---|
| `1.234,56` | Stays text (not a valid US number) | Number 1234.56 |
| `1,234.56` | Number 1234.56 | Stays text |
| `03/04/2026` | 4 March 2026 is wrong, it reads as March 4 (month first) | 3 April 2026 (day first) |
| `13/04/2026` | Stays text (month 13 does not exist) | 13 April 2026 |
In the third row, the same text gives two different valid dates. Nothing warns you. The values are plausible in both cases, so the error survives unless you check.
The silent date swap
A date such as 03/04/2026 is ambiguous. A file with many dates often contains a few where the first number is above 12, such as 13/04/2026. In a month-first locale those cells stay as text, while the others convert to dates. The column ends up as a mix of real dates and text. That mix is a strong sign that the day and month order does not match the locale.
Two ways to detect the mix:
- Dates are right-aligned by default and text is left-aligned. A column with both alignments is suspect.
- Use
=COUNT(A2:A)to count real numbers and dates, and=COUNTA(A2:A)to count all non-empty cells. If the two differ, some cells did not convert.
Choosing the right fix
You have three options. Pick based on how often you import files like this.
| Option | When to use it | Trade-off |
|---|---|---|
| Change the spreadsheet locale before importing | One-off import, the whole spreadsheet matches the file's region | Changes how every other date and number in the spreadsheet displays |
| Import into a spreadsheet with the matching locale, then copy the data | Mixed regions in one workflow | Extra step, and pasted values must be checked |
| Turn conversion off and convert with formulas | Ambiguous or mixed data, or when you need full control | More work, but explicit and repeatable |
Turning conversion off keeps every cell as text, exactly as written in the file. You then convert on your terms. For a date column in day/month/year form, this formula builds a real date regardless of locale:
=ARRAYFORMULA(DATE(RIGHT(A2:A,4), MID(A2:A,4,2), LEFT(A2:A,2)))This assumes every value has the fixed form dd/mm/yyyy, with two-digit day and month. If days and months can have one digit, split the text on the slash instead, for example with SPLIT. Blank cells at the bottom of the range will produce errors with this formula, so limit the range to the filled rows.
To fix a number that arrived as text because of the decimal separator, swap the characters and convert:
=VALUE(SUBSTITUTE(SUBSTITUTE(A2,".",""),",","."))This turns 1.234,56 into 1234.56. The result is a number in any locale, because the formula uses a period as the decimal separator in the formula text itself. It only suits a single cell that follows the European pattern. A column mixing both patterns needs a different approach.
Locale and formulas
Locale also affects formulas you type or paste. In locales that use a comma as the decimal separator, the argument separator in formulas is a semicolon. A formula such as =IF(A1>0, "yes", "no") that works in a US spreadsheet may show a parse error in a German one until you write =IF(A1>0; "yes"; "no").
This matters for imports in two ways. A file that holds formulas as text, with conversion turned on, may be parsed using the destination locale's separators. Apps Script and IMPORTDATA also depend on it: the second IMPORTDATA argument is a delimiter you choose, but numbers inside the result are still read using the spreadsheet's locale.
A diagnostic routine
When an import looks wrong, work through these checks in order. Each check isolates one cause.
- Look for odd characters. Accents turned into
éor�mean encoding. Fix the file, then re-import. - Look at the alignment of numeric columns. Left-aligned numbers are text. Check the decimal and thousands separators against the spreadsheet locale.
- Compare
COUNTwithCOUNTAon date and number columns to find cells that did not convert. - Spot-check dates with day values above 12 and compare them with the source file.
- Check File > Settings > General for the locale and time zone.
- Re-import with conversion off if the data is mixed, and convert with formulas.
Common mistakes
- Assuming the file carries a locale. A CSV has no locale. The destination spreadsheet supplies it.
- Fixing the locale after importing and expecting the data to change.
- Opening a Windows-1252 file as if it were UTF-8, or the reverse, and then saving the garbled result back as UTF-8, which makes the damage permanent.
- Testing with a file where every date has a day of 12 or less, which hides the day/month swap.
- Changing the locale of a shared spreadsheet without telling others. Dates and numbers display differently for everyone.
Exercise
You import a CSV exported from a German system into a spreadsheet whose locale is United States, with "Convert text to numbers, dates, and formulas" on. The price column shows 1.234,56 left-aligned, and a date column contains a mix of right-aligned dates and left-aligned text. Names such as "Müller" display correctly. Which setting explains the problems, and what are two ways to fix them?
Show answer
The spreadsheet locale explains both problems. Names are fine, so encoding is not the cause. The US locale does not accept 1.234,56 as a number, and it reads dates as month first, so values like 13/04/2026 cannot convert and stay as text, while ambiguous values like 03/04/2026 silently become the wrong date. Fix 1: set the spreadsheet locale to Germany (File > Settings > General > Locale), delete the imported data, and import again. Fix 2: import with conversion off so everything stays text, then convert with formulas such as DATE with LEFT, MID and RIGHT for dates and VALUE with SUBSTITUTE for prices.
Exercise
After an import, "café" appears as café in several cells. Is this an encoding problem or a locale problem, and what do you do?
Show answer
It is an encoding problem. The file is UTF-8 but was read as a single-byte encoding such as Windows-1252. Re-export or convert the file as UTF-8 and import it again. If the file is in Drive, you can instead read it with Apps Script and name the charset in getDataAsString. Changing the spreadsheet locale will not help.