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
 Forum for Origin C
 Need Help, merging a lot of workbooks

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
bbb208 Posted - 07/15/2013 : 12:07:49 AM
I am using Origin 9. These days, I am dealing with a lot of data. There are tens of workbooks with the sample columns (not worksheets in a workbook) in a folder. I have to copy, pase, copy, paste...to merge them together
I just found that Origin C could do that. Anybody could give me a Origin c script here?
Thanks a lot.
5   L A T E S T    R E P L I E S    (Newest First)
origjuhu Posted - 07/24/2013 : 12:06:13 PM
create a new origin file in the codebuilder, then compile it and then you can just run the function from labtalk / the command window
bbb208 Posted - 07/17/2013 : 12:41:08 PM
Hi,rlewis,

Could you tell me how to use this step by step?

I tried a lot of times, but I still failed.

quote:
Originally posted by rlewis

The following function is designed to loop through all workbooks in the active folder and copy all columns of the first worksheet of each workbook into columns of a single worksheet of a newly created workbook.

On Success ... returns the name of the new workbook created.
On Failure ... returns an appropriate error message.

Hopefully this will work for you ...


void MergeWorkbookData()
{
	WorksheetPage wP;
	if(wP.Create("origin", CREATE_HIDDEN)==false)
	{
		out_str("Workbook Create Fail ...");
		goto ErrorExit;
	}
	string strWbkName=wP.GetName();
	Worksheet Wks(wP.Layers(0));
	if(Wks.IsValid()==false)
	{
		out_str("Worksheet Validation Fail ...");
		goto ErrorExit;
	}
	
	// Delete all columns in the Worksheet Wks ..
	for(int i=(Wks.GetNumCols()-1);i>=0;i--)
	{
		Wks.DeleteCol(i);
	}
	Folder Fld=Project.ActiveFolder();
	foreach(PageBase pB in Fld.Pages)
	{
		if(pB.GetType()!=EXIST_WKS)
		{
			continue;
		}
		if(strWbkName.CompareNoCase(pB.GetName())!=0)
		{
			Page pG(pB);
			if(pG.IsValid()==false)
			{
				out_str("Workbook Validation Fail ...");
				goto ErrorExit;
			}
			Worksheet Wk1=pG.Layers(0);
			if(Wk1.IsValid()==false)
			{
				out_str("Worksheet Validation Fail ...");
			}
			for(int j=0;j<Wk1.GetNumCols();j++)
			{
				int ColIndex=Wks.AddCol();
				if(ColIndex==-1)
				{
					out_str("Worksheet AddCol function fail ...");
					goto ErrorExit;
				}
				if(Wk1.CopyTo(Wks, j, j, 0, Wk1.GetNumRows(), ColIndex, -1)!=0)
				{
					out_str("Worksheet CopyTo function fail ...");
					goto ErrorExit;
				}
			}
		}
	}
	out_str("Job Done ... Data Collated into Workbook "+strWbkName);
	return;
ErrorExit:
	if(wP.IsValid()==true)
	{
		wP.Destroy();
	}
}


rlewis Posted - 07/15/2013 : 5:55:21 PM
The following function is designed to loop through all workbooks in the active folder and copy all columns of the first worksheet of each workbook into columns of a single worksheet of a newly created workbook.

On Success ... returns the name of the new workbook created.
On Failure ... returns an appropriate error message.

Hopefully this will work for you ...


void MergeWorkbookData()
{
	WorksheetPage wP;
	if(wP.Create("origin", CREATE_HIDDEN)==false)
	{
		out_str("Workbook Create Fail ...");
		goto ErrorExit;
	}
	string strWbkName=wP.GetName();
	Worksheet Wks(wP.Layers(0));
	if(Wks.IsValid()==false)
	{
		out_str("Worksheet Validation Fail ...");
		goto ErrorExit;
	}
	
	// Delete all columns in the Worksheet Wks ..
	for(int i=(Wks.GetNumCols()-1);i>=0;i--)
	{
		Wks.DeleteCol(i);
	}
	Folder Fld=Project.ActiveFolder();
	foreach(PageBase pB in Fld.Pages)
	{
		if(pB.GetType()!=EXIST_WKS)
		{
			continue;
		}
		if(strWbkName.CompareNoCase(pB.GetName())!=0)
		{
			Page pG(pB);
			if(pG.IsValid()==false)
			{
				out_str("Workbook Validation Fail ...");
				goto ErrorExit;
			}
			Worksheet Wk1=pG.Layers(0);
			if(Wk1.IsValid()==false)
			{
				out_str("Worksheet Validation Fail ...");
			}
			for(int j=0;j<Wk1.GetNumCols();j++)
			{
				int ColIndex=Wks.AddCol();
				if(ColIndex==-1)
				{
					out_str("Worksheet AddCol function fail ...");
					goto ErrorExit;
				}
				if(Wk1.CopyTo(Wks, j, j, 0, Wk1.GetNumRows(), ColIndex, -1)!=0)
				{
					out_str("Worksheet CopyTo function fail ...");
					goto ErrorExit;
				}
			}
		}
	}
	out_str("Job Done ... Data Collated into Workbook "+strWbkName);
	return;
ErrorExit:
	if(wP.IsValid()==true)
	{
		wP.Destroy();
	}
}
bbb208 Posted - 07/15/2013 : 12:20:02 AM
To be clear, I just need to copy the data of workbook2, and paste it at the end of workbook1. then workbook3 at the end of the new workbook1, without labels (They have the same labels).

So, I just need to connect all the workbooks one by one.


quote:
Originally posted by rlewis

How do you want the merge to work ..
Please Specify ...

rlewis Posted - 07/15/2013 : 12:13:20 AM
How do you want the merge to work ..
Please Specify ...

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