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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Merging Worksheets

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Drbobshepherd Posted - 06/29/2012 : 11:06:30 AM
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
1   L A T E S T    R E P L I E S    (Newest First)
Kathy_Wang Posted - 07/03/2012 : 04:34:26 AM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000