3.6.4 Re-Import

Version Info

Minimum Origin Version Required: Origin 8.5.1


Origin improve Re-Importing for the data format type in File: Import submenu. From 8.5.1, Re-Import supports the user define data format file. The following is an example on how to create an X-Function to import a binary file to Worksheet with the re-import options.


  1. New an X-Function named impuser like the following picture.
    XF impuser.png reimp variable for internal used to specify this X-Function be called from the 1st importing or re-importing.
    reimportable also for internal used to specify this X-Function if can do reimport. So the value in Data column should be 1.
    The two variables both are hidden on dailog. See "V:0" in Option String column. This option used to set control as hidden.
  2. Open this X-Function in Origin Code Builder. Add the following codes to impuser function:
    Worksheet wks;
    okxf_resolve_string_get_origin_object(orng.GetDescription(), &wks);
    //Fill target page with numbers
    _import_to_wks(fname, options, wks);
    // add import information for reimport
    add_import_info(wks, fname, options, orng, reimp);
  3. Copy the following funtions to the line after //put your own support static functions here.
    //put your own support static functions here
    #include <..\OriginLab\fu_utils.h>
    static void add_import_info(Worksheet& wks, const string& fname, TreeNode& options, const Range& orng, int reimp)
    	// save X-Function name into options tree
    	fuSetXFunctionName(options, "impuser");
    	TreeNode tnUsingFilter; // filter is none
    	double dDefault = 0;
    	if ( fuGetDouble(options, IDE_DISP_IMP_ORIGINVER, dDefault) )
    		tnUsingFilter = options;
    	Tree trInput;
    	TreeNode trRange = trInput.AddNode("Range");
    	if (!trRange.SetDataRange(orng))
    	if (!impinfo_AddFile(wks, fname, NULL, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC, tnUsingFilter, 1, trRange, reimp))
    static bool _import_to_wks(const string& fname, TreeNode& options, Worksheet &wks)
    	if ( !wks.IsValid() ) 
    		return false;
    	file fIn;	
    	if( fIn.Open(fname, file::modeRead | file::shareDenyWrite) == FALSE ) 
    		return false;
    	vector vv(10);
    	fIn.Read(vv, 10 * sizeof(double));	
    	if( wks.GetNumCols() == 0 )
    		wks.SetSize(-1, 1);
    	Column col = wks.Columns(0);
    	vectorbase &vb = col.GetDataObject();
    	vb = vv;
    	return true;
  4. Put the codes below into impuser_make_tree function to construct options tree. If want to remove options tree to keep X-Function simple, you can add "V:0" for this variable in Option String column in X-Function Builder to hide this control. But cannot remove this variable since re-import need put some useful information into this tree.
    if(0 == strcmp(lpcszVarName, "options") )
    	// add import mode related treenodes		
    	constructOptionsForXF(tr, false, true);
  5. Click Compile button on the top of this X-Function.

Import and Re-Import

  1. In Origin Code Builder, new a c/cpp file and copy the following codes to it. This function used to write a data array to a *.dat file. This file will be used to do import in the below step. Click Build toobar button to compile and link.
    void write_binary_file(double dd)
    	string fname = GetOriginPath(ORIGIN_PATH_USER) + "TestFile.dat";
    	file fIn;	
    	if( fIn.Open(fname, file::modeWrite | file::modeCreate) == FALSE ) 
    	vector vData;
    	vData += dd;
    	fIn.Write(vData, sizeof(double)*vData.GetSize());	
  2. Run "write_binary_file 0" in Command window to create file TestFile.dat under Origin User File Folder and write data 1,2,... 10 to file.
  3. Run "impuser -d" in Command window and click OK button to import this file.
  4. Run "write_binary_file 10" in Command window to rewrite data 11,12,...20, into the same data file.
  5. Choose Origin menu File: Re-Import Directly to do re-import.