CSV imports with DataGrab
A quick walkthrough of a CSV import
Prepare the CSV file
CSV (Comma-separeated values) files can created manually using a text editor, or is a common export format for many other applications, especially spreadsheets.
From the ExpressionEngine Control Panel, go to Add-Ons > Modules and choose the AJW DataGrab module.
DataGrab has the option to import different types of data. Choose CSV and click on “Create new import”
Choose which channel to import the data into, and then tell DataGrab about your file. If the first row of data contains titles and should not be imported select the checkbox.
The settings will be checked and a preview of the data file will be shown, displaying a summary of the columns of the CSV file. If anything is wrong, you can go back to the previous step and adjust the settings.
If things look correct, click on “Configure Import”.
Configure Import 1
The first stage is to choose which columns to use for the entry’s title and date. The columns from the CSV file will be displayed nin the pull-down menus to select from.
Configure Import 2
Then, we need to assign values to the chosen channel’s custom fields. Here, we’ve assigned 3 columns of the CSV file to custom fields.
Configure Import 3
We can add categories to each imported entry.
Configure Import 4
We can tell the module what to do if an entry already exists. This is especially useful if we want to periodically re-run the import. The best way to do this is to import a unique value into a custom field (we’ve called it GUID above). This unique value could be an id, a url specific to the entry, a stock control number, or just something as simple as the title.
If the module encounters a duplicate entry, we can tell it ignore it and not import it, or we can get it to check to see if anything has changed and updates the existing record.
Sometimes, we want to delete entries that are not in the current import file. By adding a timestamp we can see when a record was last updated. We can then delete older entires if desired.
Configure Import 4
Finally, we can specify the author of the entry and add a time offset if required.
Clicking “Do Import” will start the process and the results will be displayed.
If we want to re-run the import at a kater date we can save it, giving it a title and description.
Using a saved import
Saved imports can be accessed from the module’s homepage and can be modified and run. Saved imports can also be run from outside the Control Panel using, for example, a cron job to automate the process.