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.
reimp variable for internal used to specify this X-Function be called from the 1st importing or re-importing.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);
//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)) return; if (!impinfo_AddFile(wks, fname, NULL, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC, tnUsingFilter, 1, trRange, reimp)) return; } 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)); fIn.Close(); if( wks.GetNumCols() == 0 ) wks.SetSize(-1, 1); Column col = wks.Columns(0); vectorbase &vb = col.GetDataObject(); vb = vv; return true; }
if(0 == strcmp(lpcszVarName, "options") ) { // add import mode related treenodes constructOptionsForXF(tr, false, true); }
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 ) return; vector vData; vData.Data(1,10,1); vData += dd; fIn.Write(vData, sizeof(double)*vData.GetSize()); fIn.Close(); }