how can I program some file import filters for several file types we use at our company?
I thought of an integrated extension of the filter choosebox in the file-open dialog (e.g. *.xls; *.txt). We use severel text files with different encodings, comments and data formats. So by simply choosing the file type, the files should be read in into a workbook and for example the comments and units should be filled in.
we use the normal Origin 7 version (till now not the PRO Version).
In version 8 we plan to make it easier for users to add file types to Origin's File Open dialog and File Import menu. You tell Origin what extensions are associated with your files and then write your import routine in Origin C. Origin will handle the call to your import routine from File Open, File Import, and drag-and-drop.
Meanwhile, you can set up your own filters in Origin 7 with a little effort. There are several approaches but I'll just discuss the method that seems easiest to me. In the following LabTalk script I assume you have two types of files, ASCII (*.dat, *.txt) and Excel (*.xls). I also assume that you have a template ready for each type (AsciiTemplate.otw and ExcelTemplate.otw) with the appropriate ASCII options already set up. Put the scripts in the [Main] section of Custom.ogs and launch them with the Custom Routine button.
run.section(File,Init); // initialize the file dialog fdlog.dlgName$="Custom import"; // dialog title fdlog.numTypes=4; // number of extensions fdlog.type1$="[ASCII (*.dat)] *.dat"; fdlog.type2$="[ASCII (*.txt)] *.txt"; fdlog.type3$="[Excel (*.xls)] *.xls"; fdlog.type4$="[All files (*.*)] *.*"; if(fdlog.open(A)==1) break 1; %B=fdlog.path$; %Z=%B%A; %A=Origin; // fdlog.deftype=extension number of selected file switch (fdlog.deftype) { case 1: %A=AsciiTemplate; break; case 2: %A=AsciiTemplate; break; case 3: %A=ExcelTemplate; break; default: break; }; win -t D %A; // open the appropriate template open -wc %Z; // import the file
Consult the fdlog object in the LabTalk programming guide for tweaking options.