Hinweis:Dieser Abschnitt ist nur in englischer Sprache verfügbar. Wir bitten um Ihr Verständnis.

2.7.1.2 Workbook Manipulation

Origin provides the capabilities for workbook manipulation by using LabTalk script, such as duplicating, merging, splitting, etc.

Duplicate Workbook

To duplicate active workbook, the win -d command is used. It allows to specify a name for the duplicated workbook, and the new workbook is activated after duplicated. The command win -da is doing the similar thing, however, it keeps the active workbook active after duplicated.

// Open a project
string strOpj$ = system.path.program$;
strOpj$ += "Samples\LabTalk Script Examples\Loop_wks.opj";

doc -o %(strOpj$);

// Activate the workbook S2Freq1
win -a S2Freq1;

// Duplicate this workbook, and name it "MyCopy"
// And this new workbook will be activated
win -d MyCopy;

// Duplicate the MyCopy workbook, and name it "MyCopy2"
// But keep MyCopy still activated
win -da MyCopy2;

Merge Workbooks

To merge multiple workbooks into one new workbook, the X-Function, merge_book, is available.

// Open a project
string strOpj$ = system.path.program$;
strOpj$ += "Samples\LabTalk Script Examples\Loop_wks.opj";

doc -o %(strOpj$);

// Activate Sample1 folder
pe_cd /Sample1;

// Merge two workbooks (S1Freq1 and S1Freq2) in two subfolders
// User the source workbook name for the worksheet name in the merged workbook
merge_book fld:=recursive rename:=sname;

// Activate Sample2 folder
pe_cd /Sample2;

// Merge two workbooks (S2Freq1 and S2Freq2) in two subfolders
// User the source workbook name for the worksheet name in the merged workbook
merge_book fld:=recursive rename:=sname;

// Activeate the root folder
pe_cd /;

// Two new workbooks are created from the above script
// The names of these two workbooks begin with "mergebook"
// Now, merge these two workbooks into a new workbooks
// The worksheets in the final result workbook will name
// by using the original worksheet name
merge_book fld:=project single:=0 match:=wkbshort key:="mergebook*" rename:=wksname;

Split Workbook

The example above is merging multiple workbooks into one workbook. It is also able to split a workbook into multiple workbooks, which contain single worksheet. The wsplit_book X-Function is designed for this purpose.

// Open a project
string strOpj$ = system.path.program$;
strOpj$ += "Samples\COM Server and Client\Basic Stats on Data.opj";

doc -o %(strOpj$);

// There are three worksheets in the active workbook, RawData
// Now split this workbook into three workbooks
// And each workbook will contain one worksheet from the original workbook
wsplit_book fld:=active;