Sub topic 1
Four ways to get a file's data into Google Sheets
You have an Excel workbook or a CSV file, and you need its data in Google Sheets. Google Sheets offers four routes for this. They differ in where the file lives, what happens to existing data, whether the result updates itself, and how much control you get over parsing. Choosing the right route before you start avoids most import problems.
This chapter gives you the map. Later chapters cover each route's settings in detail.
Prerequisites
This chapter assumes you already know:
- How to work in Google Sheets: cells, rows, columns, and multiple sheets (tabs) in one spreadsheet.
- How to upload a file to Google Drive and find it again.
- What a CSV file is (plain text, one record per line, fields split by a separator such as a comma) and what an Excel workbook is (an .xlsx or .xls file that can hold several sheets, formatting, and formulas).
- Basic formulas such as
TRIMandTEXT. They appear in later chapters on cleanup, and one appears briefly below.
You do not need to know Apps Script. The one script in this chapter is short, and you can copy it as is.
The four routes at a glance
The routes are:
- File > Import. You pick a file from your computer, Drive, or an upload, then choose how and where the data is placed.
- Opening the file from Drive. You open an Excel or CSV file stored in Drive and let Google Sheets convert it.
- The
IMPORTDATAfunction. A formula fetches a CSV or TSV file from a public URL. - Apps Script. A short script reads a file from Drive, parses it, and writes it to a sheet.
| Route | Source of the file | Result updates itself? | Control over placement | Best for |
|---|---|---|---|---|
| File > Import | Upload, My Drive, shared files | No, it is a one-time copy | High: new, replace, or append | One-off loads and adding data to an existing sheet |
| Open from Drive | A file already in Drive | No | Low: creates a new spreadsheet | Quickly looking at a file |
| `IMPORTDATA` | Public URL only | Yes, it refreshes periodically | Fixed: the formula's cell and the area below and to the right | Published data feeds |
| Apps Script | Drive (or a URL fetch) | Only if you schedule it | Full: you write the logic | Repeated, automated loads |
Two points in the table cause most confusion. The first is that File > Import and opening from Drive both produce a copy, so changing the original file later does not change your sheet. The second is that IMPORTDATA is the only route that is live by default, and it only works when the file is reachable without signing in.
Route 1: File > Import
In an open spreadsheet, choose File > Import. A dialog lets you pick a file from My Drive, Shared with me, Recent, or the Upload tab. After you choose a file, the dialog shows its settings.
The most important setting is the Import location. It decides what happens to data you already have:
- Whether the file becomes a new spreadsheet or lands in the current one.
- Whether it replaces existing content or sits beside it.
- Whether it is added below existing rows.
For delimited text files you also get a Separator type and a checkbox about converting text to numbers, dates, and formulas. Those options are covered in the chapters on import locations and separators. For now, remember that this route is the only one that lets you add rows to a sheet that already has data in it.
Use it when:
- You have a file on your computer and want its data in a specific place.
- You are adding a new month of data to an existing sheet.
- You need to choose the separator yourself.
Route 2: Opening a file from Drive
If the file is already in Drive, you can open it directly. The behavior depends on the file type.
For an Excel file, double-clicking it in Drive normally opens it in the Sheets editor in Office editing mode. You see the grid, but the file is still an .xlsx. Edits save back into that Excel file. To get a native Google Sheets file you must choose File > Save as Google Sheets, which creates a separate converted copy and leaves the original alone.
For a CSV file, right-click it in Drive and choose Open with > Google Sheets. Google Sheets creates a new spreadsheet with the data parsed into columns. The file's separator is detected automatically, and you cannot override that guess at this point.
This route gives you the least control. You cannot append to an existing sheet or pick a delimiter. Its advantage is speed: two clicks, and the data is on screen. If the parsed result looks wrong, switch to Route 1 and set the options yourself.
A converted Excel file can differ from the original. Features such as some formulas, pivot tables, charts, and macros may change or stop working. The chapter on converting Excel workbooks covers what to check.
Route 3: The IMPORTDATA function
IMPORTDATA fetches a CSV or TSV file from a URL and spills its contents into the cells below and to the right of the formula. Type this in a cell:
=IMPORTDATA("https://example.com/data.csv")If the file uses another delimiter, such as a semicolon, pass it as the second argument:
=IMPORTDATA("https://example.com/data.csv", ";")Things to know before you rely on it:
- The URL must be reachable without logging in. A link that opens a sign-in page returns an error, not data.
- The cells that receive the data must be empty. If any cell in the output area holds content, the formula shows a
#REF!error, with a message that the result would overwrite existing data. - It refreshes on its own schedule, which you cannot set. Google controls the refresh interval, so do not use it where you need to know exactly when the data was fetched.
- You get no import options. Sheets decides how to parse values, so dates and numbers can arrive converted in ways you did not choose.
- Because it is a formula, the data lives in the sheet only as long as the formula does. If you need to keep a snapshot, copy the range and use Paste special > Values only.
The IMPORTDATA chapter covers these points in more detail.
Route 4: Apps Script
Apps Script is Google's JavaScript-based scripting environment for Workspace. It lets you write the import yourself. The following function reads a CSV file from Drive by its ID, parses it, and writes the rows into a new sheet.
To use it, open a spreadsheet and choose Extensions > Apps Script. Paste the code, replace YOUR_FILE_ID with the ID from the file's Drive URL (the long string between /d/ and the next /), and run the function. Google asks you to authorize the script the first time.
function importCsvFromDrive() {
const fileId = 'YOUR_FILE_ID';
const csvText = DriveApp.getFileById(fileId).getBlob().getDataAsString('UTF-8');
const rows = Utilities.parseCsv(csvText);
const sheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet('Imported');
sheet.getRange(1, 1, rows.length, rows[0].length).setValues(rows);
}Each line does one job:
DriveApp.getFileById(fileId)finds the file, andgetBlob().getDataAsString('UTF-8')reads it as text. The'UTF-8'argument is the character encoding, so it must match how the file was saved.Utilities.parseCsv(csvText)turns the text into a two-dimensional array: an array of rows, each an array of cell values. Every value is a string.insertSheet('Imported')adds a new tab. This call fails if a tab namedImportedalready exists, so rename or delete the old tab before you run the function again.getRange(...).setValues(rows)writes the whole array in a single call. Writing all rows at once is much faster than writing cell by cell.
The script assumes every row has the same number of fields as the first row. A ragged file makes setValues fail with a size mismatch error.
Because parseCsv returns strings, values are not converted at that stage. When setValues writes them, Sheets applies its usual parsing, so a value like 00123 can still become the number 123. The next chapters explain this type conversion and how to stop it.
The main reason to choose this route is repetition. Once the function exists, you can attach a time-driven trigger so that it runs every night, or add logic that cleans the data as it is loaded.
Choosing a route
Two questions settle most decisions. The first is whether the data is a one-time copy or must stay current. The second is whether you need to control placement and parsing.
Some practical rules follow from the flow:
- Adding rows to an existing sheet means File > Import with the append option.
- An Excel workbook with several sheets can go through File > Import or be opened from Drive. Both convert it, with the same caveats.
- A file you cannot make public cannot use
IMPORTDATA. Use Route 1 or Route 4 instead. - If you do the same import more than a few times, the script pays for itself.
Common mistakes when choosing
- Expecting a live link from File > Import. It copies the data once. Use
IMPORTDATAif you need a live connection to a public file. - Editing the Excel file in Office editing mode and expecting a Sheets file. The file stays an .xlsx until you use Save as Google Sheets.
- Using
IMPORTDATAon a private Drive file. The function cannot sign in, so it fails. - Trusting the first look. Every route can change how values appear. Always compare a few rows against the source, especially IDs, dates, and codes. Leading zeros are a common casualty, and a quick formula like
=TEXT(A2, "00000")can restore a five-digit code once you know the problem exists.
Exercises
Exercise
You receive a CSV file by email every month. You want to add each month's rows below the rows already in a sheet named "Sales". Which route do you use, and why not opening from Drive?
Show answer
Use File > Import with the append option (Append to current sheet). Opening from Drive always creates a new spreadsheet and gives no way to place the data into an existing sheet, so you would have to copy and paste the rows yourself.
Exercise
A colleague puts =IMPORTDATA("https://drive.google.com/...") in a cell for a private file and gets an error. What is the likely cause, and what are two other routes that would work?
Show answer
IMPORTDATA can only fetch files that are reachable without signing in, and a private Drive file requires authentication. File > Import (pick the file from Drive) or an Apps Script function that uses DriveApp.getFileById would both work, because they run with the user's own permissions.
Exercise
You open an .xlsx file by double-clicking it in Drive, make edits, and later find that "the Google Sheets version" is missing. Explain what happened.
Show answer
Double-clicking opens the file in Office editing mode, so you edited the .xlsx itself and no Google Sheets file was created. To make a native Google Sheets file you need File > Save as Google Sheets, which creates a separate converted copy.