Origin 2023b adds a new Data Connector feature—Duplicate Sheet with More Files—that allows you to import additional data into your workbook using the same Post import Script. This allows you to customize one set of data to your specifications and then allows you to quickly apply them to all subsequent data sets. The addition of this feature continues to improve Origin by streamlining the import and data processing functionality.
In this post we will show an example using this feature.
The data used in this example can be found in Origin’s Help: Open Folder: Sample Folder …\Samples\Batch3.
I have some weather data from Logan Airport that I would like to plot and analyze. The problem is that the X data is in the date-time format but I need just the time portion. I want to import the data and create a new column that just has the time information.
Here is what the raw data looks like:
Import and Post Import Script
Now that we’ve defined our goal, let’s import our data using the CSV Data Connector. Activate an empty workbook and select Data: Connect to File: Text/CSV. We are going to start with one file, Logan Airport Weather 2022-01-01.csv. For this example, we are going to keep the default settings. What we want to change is the Post Import Script. The button to the left of “OK” opens the “Other Options” dialog and it is here we can enter our LabTalk script that executes after the data is imported. The following code is pasted into the Post Import LabTalk Script field:
string str$=page.info.system.import.filename$; //save filename in a string string strDate$=mid(str$,23,10)$; //modify the string to get just the date wks.userparam(++File Date); //create user parameter called File Date Col(A)[File Date]$=strDate$; //store the date string in col A File Date parameter Col(5)=Col(A)-date(strDate$, "yyyy-MM-dd"); //convert the date string to a Julian Date value and subtract it from col A wks.col5.lname$="Time"; //set the Long Name of column E to "Time" wks.col5.format=3; //set the Format of column E to time wks.col5.subformat=1; //set the time display of column E to HH:mm
The script takes the date information from the filename and creates a new User Parameter Row called File Date and adds the date information to that row. Then, the date string is converted into a date and is subtracted from column A, the date-time column, and the results are added to column 5. Column 5 is named “Time” and then set to the Time format with HH:mm display. Click “OK” for both dialogs to initiate the import.
Note: if you need to make further changes to the script, you can click green Data Connector icon and select Post Import Script.
For example, we can go back and add this line to the script to change the column designation from Y to X:
wks.col5.type=4; //this will change column E from E(Y) to E(X2)
Batch Processing Additional Data
Now that we have customized our first data sheet, we can import the data from other dates into the same workbook using the same LabTalk script. This method will batch import our additional files with the Data Connector Post Import Script. Click the Data Connector Icon and select Duplicate Sheet with More Files... Add the other three CSVs in Batch3 and import them.
You can change the Source to Files in Specified Folder to import all the files in that folder instead of selecting individual files.