Sub topic 1
Four Ways to Get a File's Data into Google Sheets
Google Sheets can receive data from Excel workbooks and delimited text files in several ways. The best method depends on whether you need a one-time import, a live connection to a public URL, or a repeatable process.
Prerequisites
This chapter assumes that you can create sheets, select ranges, and use basic formulas. You should also know how to upload files to Google Drive and understand the difference between a CSV file and an Excel workbook.
Choose the Import Method
The four methods have different strengths:
| Method | Best for | Main limitation |
|---|---|---|
| File > Import | A controlled, one-time import | Requires manual setup |
| Open an Excel file in Drive | Quickly reviewing or converting a workbook | Some Excel features may change |
| `IMPORTDATA` | Loading a public CSV or TSV from a URL | Works only with reachable text files |
| Apps Script | Repeatable imports from Drive | Requires script setup and authorization |
The File > Import dialog gives the most control over where data goes. Opening an Excel file is fastest when you want to inspect or convert the whole workbook. IMPORTDATA is useful when the source is published online. Apps Script is useful when the file is stored in Drive and the import must be repeated.
File > Import
For a local CSV, TSV, or Excel file, open a spreadsheet and select File > Import. Upload the file, then choose the import location:
- Create new spreadsheet makes a separate spreadsheet file.
- Insert new sheet adds the imported data as a new tab.
- Replace spreadsheet replaces the contents of the current spreadsheet.
- Replace current sheet replaces the selected tab.
- Append to current sheet adds rows below existing data.
- Replace data at selected cell places the imported range at the selected location.
Choose carefully. Replace options can remove existing data, while append can create duplicate rows if you import the same file more than once.
For a delimited file, Google Sheets asks for a separator. Choose comma, tab, semicolon, or another delimiter that matches the source. If the preview puts all fields into one column, the separator is probably wrong.
The conversion option controls whether values that look like numbers, dates, or formulas are converted into spreadsheet types. Conversion makes calculations easier, but it can damage identifiers. For example, a product code such as 00127 may become the number 127.
Opening and Converting Excel Workbooks
You can also upload an .xlsx or .xls file to Drive and open it with Google Sheets. The file initially remains an Excel file. To create a native Google Sheets file, select File > Save as Google Sheets.
Conversion may change workbook behavior. Check formulas, charts, pivot tables, formatting, macros, external links, and unsupported Excel features. Keep the original Excel file as a reference before editing the converted copy.
Loading a Public File with `IMPORTDATA`
When a CSV or TSV file is available at a public URL, enter this formula in an empty cell:
=IMPORTDATA("https://example.com/data.csv")The formula fills cells below and to the right with the file contents. For a semicolon-separated file, specify the delimiter:
=IMPORTDATA("https://example.com/data.csv", ";")This method can refresh when the source changes, but it cannot access a private Drive file merely because you can access that file in your browser.
Automating a Drive Import
Apps Script can read a CSV from Drive and write its rows into a new sheet:
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);
}Replace YOUR_FILE_ID with the ID from the Drive file URL. The first run requires authorization. This script assumes that the CSV has at least one row and that every row has the same number of columns.
Exercise
Exercise
You receive a private CSV in Drive every week and need to import it into a new tab with the same steps each time. Which method should you choose, and why?
Show answer
Use Apps Script. It can read the Drive file by ID, parse the CSV, and write the values into a new sheet in a repeatable process.