FlatTextToTable command: automatically import lists from TXT or CSV file to Excel table
XLTools Automation tool allows you to automate tasks in Excel by creating automation commands in a table, without having to create VBA macros.
Before you begin, add the Automation tool to Excel
Automation is one of the 20+ features within XLTools Add-in for Excel. Works in Excel 2019, 2016, 2013, 2010, desktop Office 365.

Step-by-step example: how to use the FlatTextToTable command
Say, you get a summary of product orders in a text file. But this file is structured as a list, and you want to put this data into a crosstab table in Excel. Every day you get a new text file with orders, and you need to import this data to Excel again and again.
Feel free to download the sample file used in this tutorial.
1. Insert the FlatTextToTable command
- Let’s take a look at the file "Orders-source-file-en.txt" you want to import to the Excel table.
- Items in the list follow the same structure: Order ID, Date, Customer, Amount.
- There is one blank line between the orders.
- Open the folder with the source text file
In the same folder create an Excel spreadsheet
Name one of the worksheets, for example, “AUTO”. This worksheet will hold automation commands.
- Select a starting cell where to place the command, e.g. A1.
- Open XLTools tab
In the Automation group, open the drop-down list
Select FlatTextToTable.
- See the table with the automation command is now added on the worksheet.
2. Specify parameters and define how to extract data
XLTools.FlatTextToTable | |
---|---|
Columns: | ORDER ID,DATE,CUSTOMER,AMOUNT,Blank |
SourceFile: | Orders-source-file-en.txt |
KeepWorkbookOpen: | TRUE |
ApplyTableName: | Orders |
TableSortRange: | |
OutputTo: | NewSheet[Orders] |
What each line in this command reads:
- Columns: assign a name to each column. E.g. records from each line in the TXT file will be placed into a corresponding column. Note, that since there are blank rows in the source file, we should add a column "Blank". It’s easier to delete the column from the resulting table later on, instead of deleting all blank lines from the source file
- SourceFile: specify the source file name.
- KeepWorkbookOpen: instruct to keep the workbook open.
- ApplyTableName: assign the name "Orders" to the resulting table.
- TableSortRange:
- OutputTo: place the result on a new worksheet "Orders" in the same workbook as the automation command.
3. Execute the command and review the extracted data
- Select the table of the automation command
In the Automation group, click Execute Commands.
Review the extracted data:
- See a crosstab table generated on the new worksheet "Orders"
- Records from the TXT source file are imported into the corresponding table columns
- Note that all cells have text format, you can now assign the format you need
Done! Now you can assign a custom button to this command.
4. Assign a custom button to the command
If you need to run the command over and over again, add a custom button on the ribbon. So that next time you can execute the command in a click.
- In the Automation group, click Add Custom Buttons.
- Name the button, e.g. "Pull Invoices"
Specify the range of the FlatTextToTable command
Click Save.
- Done! The custom button will appear on XLTools tab. Now every time you click this button, you will execute the command.
Parameters and available options
When you create automation commands in Excel, this file with commands must be located in the same destination as the source data.
SourceFile:
This parameter specifies which text file to process.
- Required parameter, cannot be blank
- You can use TXT or CSV files
Options | Meaning |
---|---|
File.txt File.csv | Name of the source file. The automation file must be located in the same destination as the source file. |
C:\Documents\File.txt C:\Documents\File.csv | Specify the file path to the workbook. The automation file can be located at a different destination as the source file. |
Columns:
This parameter specifies how to name the columns, where data from the source file will be imported.
- Required parameter, cannot be blank
- Order of the columns should follow the same order of the lines in the source file
Options | Meaning |
---|---|
Column1,Column2, ColumnC | Type column names, comma separated. Usage of space after comma is possible. |
KeepWorkbookOpen:
This parameter defines whether to keep the resulting workbook open after the operation. Useful when you have a sequence of automation commands.
- Optional parameter, you can leave it blank or remove from the command altogether
Options | Meaning |
---|---|
TRUE | Keeps the workbook open. |
FALSE | Does not keep the workbook open. |
(blank) | Same as FALSE |
ApplyTableName:
This parameter assigns the name to the resulting table. The result is generated as a named formatted table.
- Required parameter, cannot be blank
- The length of a text string in a cell cannot exceed 127 characters
Options | Meaning |
---|---|
Table1 | Assign any name to the resulting table. There are some Excel limitations. |
TableSortRange:
This parameter defines whether to sort the resulting table. Sorting is A to Z.
- Optional parameter, you can leave it blank or remove from the command altogether.
Options | Meaning |
---|---|
A:A | Sort the table by values in Column A. |
OutputTo:
This parameter specifies where to place the resulting table.
- Required parameter, cannot be blank
- The length of a text string in a cell cannot exceed 255 characters
Options | Meaning |
---|---|
NewSheet[Result] | Place the result on a new worksheet named Result in the active workbook |
NewHiddenSheet[Result] | Place the result on a new hidden worksheet named Result in the active workbook |
ExistingSheet[Result!A20] | Plase the result on an existing worksheet named Result in the active workbook, place the results starting in cell A20 |
NewWorkbook[Result] | Place the result into a new workbook named Result.xlsx. The workbook will be saved in the same location as the automation file. |