The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Merging Worksheets
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Drbobshepherd

USA
Posts

Posted - 06/29/2012 :  11:06:30 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin):OriginPro 8.6.0 Sr3
Operating System: Windows XP

I found the merge_book X-function to combine several workbooks into one workbook, but understandably, there is no merge_sheet X-function because sheets can have different formats. However, if all sheets in a workbook are of identical structure, what is the best way to combine them?

DrBobShepherd

Kathy_Wang

China
159 Posts

Posted - 07/03/2012 :  04:34:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I think you could make use of the colcopy x function to copy your data from other worksheets to be in one worksheet.

You may refer to the following online help file for more information of this XF:
http://www.originlab.com/www/helponline/Origin/en/Programming/mergedProjects/X-Function/X-Function/Colcopy.html

In order to make it simpler, you may use a flow control to loop over the worksheets, here is an example for you to try:

//Book1 is the workbook contains all your worksheets
win -a Book1;
//get the number of worksheets as m, and the number of columns in each worksheet as n
int m=page.nLayers+1;
int n=wks.ncols;
//Create a new book(Book2 in this case) to store the 
newbook;
for(int i=1; i<m; i++)
{
	win -a Book1;
	page.active = i;
	int j = n*i - n + 1;
	colcopy irng:=1:$(n) orng:=[Book2]Sheet1!$(j):$(j+n-1) format:=1 lname:=1 units:=1 comments:=1 ;	
}


In addition, if you only need to copy the data but not the format and column header, you may also use wks.copy and wks.paste, an example would be:


win -a Book1;
int m = page.nLayers + 1;
int n = wks.ncols;
newbook;
for(int i=1; i<m; i++)
{
	win -a Book1;
	page.active = i;
	wks.copy(Z);
	win -a Book2;
	int j = n*i - n + 1;
	wks.paste(Z,j,1);
}


Kathy
Originlab

Edited by - Kathy_Wang on 07/03/2012 04:42:48 AM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000