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

OndrejMM

Australia
81 Posts

Posted - 07/13/2009 :  02:38:40 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi guys, Im sorry to bother you again, but I have the following problem,.. I have one workbook containing ~40 worksheets with the following names: AD-S11, AD-S22, AD-S33, BD-SS11, BD-S22, BD-S33, . XX-S11, XX-S22, XX-SS33 and I would nned to merge the all AD, BD XX data into a worksheet, e.g. the current workbook will have a AD worksheet containing data from AD-S11, AD-S22, AD-S33 worksheets; a BD worksheet will contain data from BD-S11, BD-S22, BD-S33 worksheets, . etc.,.. can you please give me some advice how to do it?
Cheers, Ondrej

rlewis

Canada
253 Posts

Posted - 07/13/2009 :  1:29:50 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
if you are willint to try OriginC ... the following should do more or less what you want ...


	void CollectWorkSheets(string strNamePrefix)
	{
		/*
			CollectSheets
			Collects All Worksheets from the current Workbook with names beginning with "strNamePrefix" into a single Workbook;
		*/
		WorksheetPage wpSource=Project.Pages(-1);
		if(wpSource.IsValid()==true)
		{
			WorksheetPage WPtarget;
			string strName=strNamePrefix;
			strName.TrimLeft();
			strName.TrimRight();
			strName.MakeLower();
			if(WPtarget.Create(strNamePrefix,CREATE_HIDDEN)==true)
			{
				Worksheet WksEmpty(WPtarget.Layers(0));
				WksEmpty.SetName("XXX"+strName);
				int NumLayers=0;
				foreach (Layer Layr in wpSource.Layers)
				{
					Worksheet Wks(Layr);
					if(Wks.IsValid()==true)
					{
						string strWksName=Wks.GetName();
						if(is_str_match_begin(strName,strWksName)==true)
						{
							NumLayers++;
							if(WPtarget.AddLayer(Layr)<0)
							{
								goto ErrorExit;
							}
						}
					}
				}
				if(NumLayers>0)
				{
					if(WksEmpty.IsValid()==true)
					{
						WksEmpty.Destroy();
					}
					string strWbk=WPtarget.GetName();
					SetDataDisplayText("Worksheets Collected in  "+strWbk);
					return;
				}
ErrorExit:		WPtarget.Destroy();
			}
		}
		SetDataDisplayText("Command Failed ...");
	}
Go to Top of Page

masterd

Australia
Posts

Posted - 03/15/2010 :  11:26:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi guys,

Im getting following errors trying to compile the above script in 7.5 Pro SR5. Is this script for version 8 maybe?

compiling...
merge worksheets.c
...(49) :Error, Member function Worksheet::SetName not defined or does not have matching prototype.
...(32) :Error, error(s) found in compiling method
...(49) :Error, general compile error
...(46) :Error, general compile error
...(39) :Error, general compile error
...(32) :Error, error(s) found in compiling function CollectWorkSheets
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 03/16/2010 :  12:17:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes ...
The code is intended for Origin 8.0 and Higher ..
Workbooks with multiple sheets were first introduced in Origin 8.0
Go to Top of Page

masterd

Australia
Posts

Posted - 03/16/2010 :  12:23:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for that.

Is there a script that could help me solve similar problem with 7.5Pro SR5 as reported here http://www.originlab.com/forum/topic.asp?TOPIC_ID=8374?

Go to Top of Page

rlewis

Canada
253 Posts

Posted - 03/16/2010 :  02:19:09 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The Following OC function is designed to collect the columns of all worksheets with names beginning with the characters in the string "strWksStem" into a single newly created worksheet (Returns the name of the new worksheet)

It works in Origin 7.5-SR6 ... Needs a little tweaking though ...


string CollectWksCols(string strWksStem)
{
	vector<string> vctWksNames;
	vctWksNames.RemoveAll();
	string strNameStem=strWksStem;
	strNameStem+="*";
	foreach(PageBase pB in Project.Pages)
	{
		if(pB.GetType()==EXIST_WKS)
		{
			string strWksName;
			if(pB.GetName(strWksName)==true)
			{
				if(strWksName.Match(strNameStem)==true)
				{
					vctWksNames.Add(strWksName);
				}
			}
		}
	}
	int NumMatches=vctWksNames.GetSize();
	Worksheet WksDest;
	if(WksDest.Create("origin.otw")==false) goto ErrorExit;
	int nCols=WksDest.GetNumCols()-1;
	for(int i=nCols;i>=0;i--)
	{
		WksDest.DeleteCol(i);
	}
	for(i=0;i<NumMatches;i++)
	{
		Worksheet Wks;
		if(Wks.Attach(vctWksNames[i])==false) goto ErrorExit;
		foreach (Column col in Wks.Columns)
		{
			Dataset dSource(col);
			if(dSource.IsValid()==true)
			{
				int i=WksDest.AddCol();
				if(i==(-1)) goto ErrorExit;
				Dataset dDest;
				if(dDest.Attach(WksDest,i)==false) goto ErrorExit;
				dDest.SetSize(dSource.GetSize());
				dDest=dSource;
			}
		}
			
	}
	if(WksDest.GetNumCols()>0)
	{
		return (WksDest.GetPage().GetName());
	}
	ErrorExit:
	if(WksDest.IsValid()==true)
	{
		WksDest.Destroy();
	}
	return ("");
}
Go to Top of Page

olsy

29 Posts

Posted - 11/09/2011 :  12:23:32 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi guys!
ive tried the first code and its copying all worksheets from the original on to a new. Do you know what could be a problem?
and second code gives an error..i also dont know why..
any idea?Please help!
string Par4plot;
WorksheetPage wpSource=Project.Pages(-1);
if(wpSource.IsValid()==true)
{
WorksheetPage WPtarget;
string strName=Par4plot;
strName.TrimLeft();
strName.TrimRight();
strName.MakeLower();
if(WPtarget.Create(Par4plot,CREATE_HIDDEN)==true)
{
Worksheet WksEmpty(WPtarget.Layers(0));
WksEmpty.SetName("XXX"+strName);
int NumLayers=0;
foreach (Layer Layr in wpSource.Layers)
{
Worksheet Wks(Layr);
if(Wks.IsValid()==true)
{
string strWksName=Wks.GetName();
if(is_str_match_begin(strName,strWksName)==true)
{
NumLayers++;
if(WPtarget.AddLayer(Layr)<0)
{
goto ErrorExit;
}
}
}
}
if(NumLayers>0)
{
if(WksEmpty.IsValid()==true)
{
WksEmpty.Destroy();
}
string strWbk=WPtarget.GetName();
SetDataDisplayText("Worksheets Collected in "+strWbk);
return;
}
ErrorExit: WPtarget.Destroy();
}
}
SetDataDisplayText("Command Failed ...");
}
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