6.6 Importing Data by Drag-and-Drop
You can import files by dropping them onto the Origin workspace, provided the key file handling components are in place. Origin ships with built-in drag-and-drop support for selected file types and you have the option -- by creating an import filter with the Origin Import Wizard -- to add drag-and-drop support for additional file types. This topic summarizes the basic things that you ought to know to make use of drag-and-drop file import.
Import code reading sequence
When files are dropped into Origin, they are handled by one of three import routines.
- The oldest method involves calling a LabTalk section in a file called DOFILE.OGS. This user-modifiable file is installed in the Origin Program Folder as part of your Origin software. This method is supported primarily to ensure backward-compatibility.
- One newer method relies on an Origin import filter for different import types. Origin ships with a number of built-in filters .OIF files in the \Filters folder of your Origin program folder. You can also create import filter by Import Wizard of Filter Manager
- Most recently, OriginLab has introduced the Data Connector concept. While drag-and-drop support for this import mechanism is not as broad as it is for Origin import filter files, Origin will give precedence to supported file types, prompting the user to choose between import by Connector or by Origin Import Filter (*.OIF) file.
When files are dropped into the Origin workspace, the following sequence occurs:
- The Origin User Files folder and then Origin Program folder are searched for a file called DOFILE.OGS. If found, the file is examined for a section named [OnOpenExtension], where Extension is the file extension of the dropped file. If found, that section is executed and the file name is passed as an argument.
- If DOFILE.OGS contains no file handling instructions for file type Extension, Origin looks first in target window, then the data file folder, and last the User Files\Filter folder, for a matching filter. If a matching filter is found, that filter is used to import the data.
- If no matching filter is found at these locations, Origin will check to see if the file type is supported by a Data Connector. If (a) a Connector exists and (b) the user has not previously declined to use a Connector for import of this file type, then the user is asked whether the Connector should be used for data import.
- If you answer Yes, the Data Connector is used for file import. If you answer No, the file will imported using the System import filter in the Origin Program folder and an entry will be written to User Files\Origin.ini disabling the prompt from showing again.
- If no Connector exists and an appropriate import filter is not found, you will be asked if you want to open the Import Wizard to attempt file import. This gives you the opportunity to interactively parse the file, extract file information and, if so desired, save the settings as an import filter.
Data Connectors and Drag-and-Drop
When you drop a supported data file onto the Origin worksheet or empty portion of the workspace, you are prompted to choose between using a Data Connector or using an import filter file, to import the dropped file:
- If you specify use of a Data Connector, a Connector will be used to import this file and all future files of this type; otherwise an import filter is used.
- You can, at any time, change this behavior by opening the Filter Manager (Preference: Import Filters Manager) and checking or unchecking the Support Drag&Drop box beside the file extension. If you clear the box and click Apply, the appropriate Data Connector will be used for import. If you check the box and click Apply, the system import filter file is used for import.
| Note: If an import filter is saved to the worksheet, the data file folder or the User Files\Filters folder, the saved filter will be used and you will not be prompted to choose between Data Connector and system import filter file.
Using the Import Wizard to Set Up D&D Import
The Import Wizard supports import of ASCII and simple Binary (an optional header section followed by a sequential binary structure) data files. If your data do not fall easily into one of those two categories, you can write your own Origin C code (User-Defined) to handle data import.
One of the chief advantages of using the Wizard to import your data files is that you can save your custom settings to a filter that can be used repeatedly to import the same or similarly-structured files. Once you've created your filter(s), subsequent files are easily imported by drag-and-drop or via the File: Open dialog box.
Origin Import Filters
When creating an import filter, the normal sequence of events is to open the Import Wizard, select a data file, then step through a sequence of Wizard pages in which you interactively parse the file, select file and window naming options, select header information to be stored and re-used, etc. When you have finalized your import settings, you can store them as an import filter (saving the filter is highly recommended if you plan to import the same or similar files in the future).
When creating an import filter, you have the option of saving the filter (a) in the Origin child window or (b) to a separate Origin Import Filter file (.OIF). An advantage of saving the filter with the child window is that the filter travels with the window itself and, thus, it becomes part of the Origin project file (OPJ) or child window file. The other option -- saving the filter as a separate .OIF file -- offers more flexibility as it allows you to choose from a number of filter files on the first page of the Import Wizard before clicking Finish (the filter contains all necessary import instructions). Both child window-based filters and OIF files support drag-and-drop file import.
Once created, an import filter can be tweaked to import files that vary somewhat in their structure, without having to completely recreate every import specification. Filters are easily shared with colleagues, allowing standardization of import file handling among different work groups or geographically-remote work sites.
Your import filter can be narrowly-defined to work only with a particular file name (or variations on that file name) or it can be broadly-defined to apply to all files with a given file extension. For instance, you might work with an instrument that automatically names data files in sequence using a scheme something like XYZ_001.CSV, XYZ_002.CSV, XYZ_003.CSV. Using the "*" wildcard character, you could broadly target the filter to all .CSV files in your data file folder by specifying that the filter apply to any file with the name "*.CSV." Conversely, you could narrowly-target the filter by specifying that the filter apply only to CSV files named "XYZ*.CSV."
Target Windows and Target Window Templates
When defining an import filter for ASCII, binary or user-defined file types, you must specify a Target Window and Target Window Template. Note that Data Types other than User-Defined are limited to Target Window = Workbook. Note, too that User-Defined allows you to bypass specifying the Target Window and Target Window Template if window creation is to be handled by your Origin C code (in which case, the code would handle window creation).
The Target Window merely specifies the type of child window that will receive the imported data. The Target Window Template, on the other hand, is a specific (named) window template with custom configuration and format settings. The Target Window Template is used when drag-and-drop import operations call for creating new windows.
Assuming that you have defined an import filter, if you drag-and-drop one or more data files into an active window and that window is of the Target Window type, then Origin will import the file(s) using the new window/new worksheet/new column settings specified in the filter. If, for instance, (1) the filter Import Mode is set to Start New Columns and (2) the file(s) are dropped onto a workbook window (the Target Window type specified in the filter), then the file(s) are imported and added as columns into the active worksheet in the active workbook. If the active sheet had empty columns, they would be filled first. In this case, the active workbook was of the correct Target Window type and each file required only the creation of new columns. No new windows needed to be created so, therefore, the Target Window Template was not used.
If the filter Import Mode had been set to Start New Books, then the first file dropped would import into the active workbook if the columns in the active sheet were empty (again -- the Target Window was of the correct type), and each subsequent file would import into new workbook windows created using the Target Window Template. Note that the Target Window Template may, or may not, be the same template that the active workbook window was based upon. However, the default Target Window Template (<Default> from the drop-down list on the Import Wizard Source page) is the default Origin worksheet or matrix template. Unless you have chosen a different default template, this would be ORIGIN.OTW (worksheet) or ORIGIN.OTM (matrix).
Built-in drag-and-drop support
All third-party file types that have build-in support are importable by drag-and-drop, owing to the fact that import filters for these file types are built into Origin. You can use the Filter Manager to specify whether the drag-and-drop import mode should be turned on/off for a specific file type. The Filter Manager can be opened by selecting Preferences: Import Filters Manager from the Origin menu.
Adding drag-and-drop support for new files
You can add drag-and-drop support for new files by defining an import filter using the Import Wizard. You will need a representative data file and you should know something about the type of data that your file contains (whether it contains ASCII or binary data, or is of another type).
Some things to consider when deciding how to target your import filter and where to save it:
- When you drag-and-drop one or more files into Origin, Origin first searches a file called DOFILE.OGS to see whether there are data handling instructions for the dropped data file (see "Import code reading sequence," above). If Origin fails to find data handling instructions for the dropped file in DOFILE.OGS, it then checks to see whether a Data Connector exists for the file type. If no Connector exists or if you decline to use the Connector for import, Origin searches these locations, in the following order, for an appropriate import filter: active child window > data file folder > User Files \Filters folder > Origin program \Filters folder. If the files are dropped into an empty portion of the workspace, there is no active child window and so the search goes directly to data file folder > User Files \Filters > Origin program \Filters folder.
- If multiple applicable filters are found in one of these locations, Origin prompts you to select a filter from the Select Filter dialog box (Note that when saving filters with the child window, you can only save one per window). If no applicable filter is found, Origin opens the Import Wizard. You then have the opportunity to create and save an import filter.
- If your data file isn't of the ASCII or simple binary types, you can still create filters by supplying data handling instructions in the form of Origin C code.
- Drag-and-drop import supports multi-file import.