6.6 Importing Data by Drag-and-Drop

Origin supports drag-and-drop import for many common file types. For historical reasons, there are multiple technologies used. When you drop a file onto an Origin worksheet or matrixsheet, there is a code-checking sequence that occurs that will determine which method is used. See Import Code Reading Sequence, below.


Note: You will not be able to drag and drop files if you are running Origin as an administrator.

Import Code Reading Sequence

When files are dropped into Origin, this sequence occurs:

  1. The oldest method -- and that which is first checked -- calls a LabTalk section in a file called DOFILE.OGS. If found, the import routine is run. While the legacy code in DOFILE may still run satisfactorily, the user should not attempt to write new import routines using this method.
  2. Next in the sequence, the active worksheet or matrixsheet is scanned for import filter information saved to the sheet (see "Save Settings for Drag-and-Drop" below).
  3. If no filter information is saved to the sheet, the data folder is checked for a matching Origin Import Filter (*.oif).
  4. If no filter is found in the data folder, the User Files\Filters folder is checked for a matching import filter. If a USER filter exists and the Support Drag&Drop filter box is checked in Filter Manager, then this filter handles import. If in addition to the USER filter, there is a filter in the SYSTEM\Filters folder and the Support Drag&Drop box is checked for the SYSTEM filter in Filter Manager, the Select Filter dialog opens prompting you to choose a filter.
  5. If no matching filter is found in User Files\Filters, the code checks to see whether there is an installed Data Connector that matches the file type. If a matching Data Connector is found, the Data Connector handles import (One exception is ASCII *.dat files; if the Support Drag&Drop filter box is checked for the SYSTEM filter in Filter Manager, the SYSTEM filter is used instead of a Data Connector).
  6. If no Data Connector is found and the SYSTEM Support Drag&Drop filter box is unchecked or does not show in Filter Manager, Origin opens an attention box asking if you want to open the Import Wizard to import the file.

This code reading sequence can be modified by setting system variable @IFS. See Notes in the next section.

Data Connectors and Drag-and-Drop

Data Connectors are Origin's newest data import technology. If you have been using an Origin Import Filter (*.oif) -based routine, it should still be fully-supported (see Note, below). However, we encourage you to try Data Connectors, particularly if you are importing Text/CSV files.

The primary advantage of using a Connector for drag-and-drop of Text/CSV is that files should be handled automatically, without the need for configuration of dialog boxes or saving of settings to the sheet or to an external filter file. This is of particular benefit to those whose files contain date-time data, as the data should be automatically recognized and formatted in the sheet on import.

Notes:
  • Import filters saved to the sheet or to the data folder as an Origin Import Filter (*.oif) file, will take precedence over use of a Data Connector.
  • User-defined filters will also take precedence over the Data Connector if the User filter's Support Drag&Drop box is checked in Filter Manager.
  • Set system variable @IFS to allow use of a System Filter for data import. Note that the System filter is generic and may not import your data to your satisfaction.

Save Settings for Drag-and-Drop

When using one of the X-Function based dialogs for file import -- those found under Data: Import from File -- you have the option of saving the current dialog box configuration to a Dialog Theme or to Save Settings for Drag and Drop.

When you Save Settings for Drag and Drop, you are saving an import filter to the sheet itself. As long as the sheet -- or a duplicated sheet is active -- you can then drop new files of identical file type and structure and have them imported cleanly into the sheet.

  1. Create a new workbook and choose a file format under Data: Import from File (e.g. Single ASCII).
  2. Choose a matching file, make sure the Show Options Dialog box is checked and click Open.
  3. Select options in the dialog so that file data will be properly parsed, then click the Dialog Theme Button.png to the right of Dialog Theme (top of the dialog) and choose Save Settings for Drag and Drop.
  • At this point, you can drop another file of like type and structure onto the active sheet (note that depending on your dialog box Import Mode settings, you may overwrite the existing data or you may start a new sheet or book) and it will be handled by the settings saved to the sheet.
  • You can also save the window as a template (File: Save Template As) and recall the window configuration -- including drag-and-drop file handling -- for later use.

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 (*.opju) or child window file (*.ogwu). The other option -- saving the filter as a standalone *.oif file -- offers the flexibility of choosing different filter settings with the same file or for using the filter with multiple workbook templates. Both window-based filters and standalone *oif filter 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).

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, the code 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 the code fails to find data handling instructions for the dropped file in DOFILE.OGS, it then searches these locations, in the following order, for an appropriate import filter: active child window > data file folder > User Files \Filters folder.
  • If multiple applicable filters are found in a folder, you are prompted 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 in these locations, the code checks for a matching Data Connector. If one is found, then you are prompted to open the Import Wizard. There, you will have the opportunity to create and save an import filter.
Drag and Drop Basics-1.png
  • 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.