The IMPORTTEXT function allows you to import data from a text-based file (such as CSV, TXT, or TSV) directly into Excel. You can specify delimiters, skip or take rows, and apply encoding or locale settings for precise control over the imported content.
Note: This feature is currently generally available to Microsoft 365 subscribers enrolled to the Insiders Beta channel, running Version 2502 (Build 18604.20002) or later in Excel for Windows.
Syntax
The IMPORTTEXT function imports data from a text-based file into Excel as a dynamic array.
The syntax of the IMPORTTEXT function is:
IMPORTTEXT(path, [delimiter], [skip_rows], [take_rows], [encoding], [locale])
|
Argument |
Description |
|---|---|
|
path (required) |
The local file path or URL of the text-based file you want to import. |
|
delimiter |
A character or string that specifies how columns are separated in the file. If omitted, the function uses tab as the delimiter. |
|
skip_rows |
A number that specifies how many rows to skip. A negative value skips rows from the end of the array. |
|
take_rows |
A number that specifies how many rows to return. A negative value takes rows from the end of the array. |
|
encoding |
The file encoding. By default, UTF-8 is used. |
|
locale |
Determines regional formatting (e.g., date, number formats). By default, the OS locale is used. |
Notes:Â
-
Import Functions do not automatically refresh. To update imported data, use the Refresh All button on the Data tab.
-
You can specify fixed-width columns by passing a comma-separated array of ascending integers in the delimiter argument.Example: =IMPORTTEXT("C:\Data\fixedwidth.txt", {1,3})
-
You can use the CHARÂ function to specify special characters for the delimiter argument.
-
You can use the IMPORTCSV function as an easier alternative for importing CSV files.
When importing a file from the web, you may need to provide credentials or sign in to access the source file. In such cases, you will be prompted to select the authentication method to use for the provided URL through an authentication dialog.
The available authentication methods are:
-
Anonymous: Select this authentication method when the content is publicly accessible and doesn’t require sign-in.
-
Windows: Select this authentication method when accessing a resource that requires your Windows credentials.
-
Basic: Select this authentication method when the resource requires a username and password.
-
Web API: Select this method if the web resource that you're connecting to uses an API Key for authentication purposes.
-
Organizational account: Select this authentication method if the resource requires organizational account credentials.
To clear permissions given during the authentication process, click on Data > Get Data >Â 'Data Source Settings...'. Then, under the 'Global Permissions' tab, select the relevant URL path and click on 'Clear Permissions'
Examples
The following examples are based on a fictitious text file path: "C:\Data\example.txt".
Return the first two rows from the source file
|
Data |
||||||||||||
|
||||||||||||
|
Formulas |
||||||||||||
|
=IMPORTTEXT("C:\Data\example.txt",,,2) |
The following illustration shows the result:
Skip the first row from the source file
|
Data |
||||||||||||
|
||||||||||||
|
Formulas |
||||||||||||
|
=IMPORTTEXT("C:\Data\example.txt",,1) |
The following illustration shows the result: