6.4.7 Importing User Defined Data Files

If the data files you wish to import are neither ASCII nor simple binary files, you can write your own Origin C functions to import the files with the Import Wizard or develop your own X-Functions to do the importing. We recommend the latter method because it has the following benefits:

  • X-Functions are easier to be accessed by LabTalk scripts
  • It is convenient to make your X-Functions accessible from Origin menu. Make sure that your X-Function name starts with as "imp" and the X-Function is saved in <user files folder>\X-Functions\Import and Export. The X-Function will be shown in the Data: Import from File menu next time Origin starts. See Customizing Data: Import from File and File: Export Menu in this chapter.
  • Sharing X-Functions with other users is very easy. Other users can drag-n-drop an .oxf file into Origin to install the X-Function. If you are a Licensed Concurrent Network user, you can even use the Group Folder feature to share any importing X-Functions with all members in the network. See Sharing Files with Multiple Clients in the Sharing Your Origin Files with Others chapter.

You can take the importing X-Functions under <Origin Program Folder>\X-Functions\Import and Export as examples when you develop your own importing X-Functions.

However, if you do want to import user-defined data files with the Import Wizard, you can develop your own Origin C functions to handle the importing.

The prototype of Origin C functions must be either one of the following:

  • int YourFunctionName(Page& pgTarget, TreeNode& trFilter, LPCSTR lpcszFile, int nFile)
  • int YourFunctionName(Layer& lyTarget, TreeNode& trFilter, LPCSTR lpcszFile, int nFile)
Note: More details on how to write such Origin C functions can be found in the Importing Data chapter in Origin C Guide.

After writing a function to handle the importing and saving it to an Origin C file, you can use it as follows:

  1. Open the Import Wizard with the Import Wizard button Button Import Wizard.png or selecting Data: Import from File: Import Wizard from the Origin menu.
  2. On the first page (the Source page) of the Wizard, select the User Defined radio button in the Data Type group.
  3. Specify the path for the imported files, if you wish to import one or more files; or, select the Clipboard radio button, if you wish to import from clipboard.
  4. Select a target window by selecting one of the radio buttons in the Target Window group. Choose a template * and an import mode, if desired. Then click Next to go to the User Defined Filters page.
  5. In the User Defined Filters page, click the Browse button Importing Simple Binary Files with the Import Wizard-1.png to the right of Origin C Source File. Navigate to the folder where your Origin C file is. Select the file and click Open to return to the Import Wizard. Enter the name of the function in the Origin C Function edit box. Then click Next to customize settings in other pages.
  6. When you finish all the settings, click Finish. Your Origin C function will be used to import the files.
*:The target window template named on the Source page of the Import Wizard is only used when new windows are created (as would happen under some conditions during drag-and-drop importing). When choosing Data: Import from File from the menu and your active window is consistent with your import filter's Target Window specification, no new window is created and a reference to the page object for the active window is passed to your function. If the active window is of a different type, a new window will be created using the specified template, and the page reference to this new window is passed.