Author |
Topic  |
|
Gandi
USA
Posts |
Posted - 12/12/2011 : 7:17:04 PM
|
I am using a workbook template which contains a worksheet script to perform a few simple operations upon ASCII import. When I use it together with the 'Import Multiple ASCII' function and import mode 'Start New Sheets', the script is executed multiple times on one worksheet. The script does not run on the remaining worksheets.
What import setting or what command in the script is required to make sure that all ASCII files are imported into separate worksheets in the same workbook, and then the script is executed once for every single worksheet?
Thanks in advance.
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 8.5.0 SR1 Operating System: Win 7 Pro, 64 bit |
|
Penn
China
644 Posts |
Posted - 12/13/2011 : 01:42:37 AM
|
Hi,
You can use the document command to loop over all worksheets in the workbook, such as
document -e LW
{
// your script for each worksheet here
}
In our latest version, Origin 8.6, you can use the Import Wizard with the script executed after each file imported. And then you can save the settings as a filter for future use. To download a free demo of this version, please see this page.
Penn |
 |
|
Gandi
USA
Posts |
Posted - 12/18/2011 : 4:29:17 PM
|
Hi Penn,
thanks for your prompt reply. I tried this in a simple example where my worksheet script contains nothing but
document -e LW { col(A) = col(A) / 10; }
However, when I import multiple ASCII files now, using import mode 'Start New Sheets', the column operation is executed n times for each sheet, where n is the number of ASCII files. In other words, in each created worksheet column A is divided by 10 not only once, but n times. This is the other extreme compared to my original problem, where column A would have been divided n times by 10 only in one sheet, while all other sheets remained untouched. |
 |
|
Penn
China
644 Posts |
Posted - 12/19/2011 : 8:38:31 PM
|
Hi,
When you run "col(A) = col(A) / 10", It will always work on the active worksheet. So, you need to activate the worksheet first, or define the range of column A for each worksheet. For example:
doc -e LW
{
int nActive = page.active; // get the active worksheet index
page.active = nActive; // activate this worksheet
col(a) = col(a)/10;
}
or
doc -e LW
{
int nActive = page.active; // get the active worksheet index
range rColA = [%H]%(nActive$)!col(a); // define the range to column A
rColA = rColA / 10;
}
Penn |
 |
|
Gandi
USA
Posts |
Posted - 12/20/2011 : 6:19:05 PM
|
Thanks, Penn. If I execute one of those code snippets in the command window after the ASCII files have been imported and the worksheets have been created I get the desired result. But if I use add this code to the worksheet script, again it gets executed n times for all worksheets.
Is there a way to import n files into different worksheets, and to then execute the script of each worksheet only for that specific worksheet (rather than all worksheets), or to run one single script after all files have been imported? (Without having to update to v8.6)? |
 |
|
Penn
China
644 Posts |
Posted - 12/21/2011 : 04:37:37 AM
|
Hi,
When I try to add script to worksheet script, and then save as template for importing data, It seems not work very well if there are a lots of files to be imported. For now, you can run the script snippet after importing all files. Or you can try the Import Wizard, and put this script snippet for post processing, then save the settings as import filter.
Penn |
 |
|
Gandi
USA
Posts |
Posted - 12/22/2011 : 4:43:35 PM
|
Thanks lots for your help, Penn! |
 |
|
|
Topic  |
|
|
|