| T O P I C    R E V I E W | 
               
              
                | OndrejMM | 
                Posted - 07/13/2009 : 02:38:40 AM  Hi guys, I’m 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
  | 
               
              
                | 6   L A T E S T    R E P L I E S    (Newest First) | 
               
              
                | olsy | 
                Posted - 11/09/2011 : 12:23:32 PM  Hi guys! i´ve 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 don´t 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 ..."); 	} | 
               
              
                | rlewis | 
                Posted - 03/16/2010 : 02:19:09 AM  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 ("");
}
 | 
               
              
                | masterd | 
                Posted - 03/16/2010 : 12:23:52 AM  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?
 
  | 
               
              
                | rlewis | 
                Posted - 03/16/2010 : 12:17:37 AM  Yes ...  The code is intended for Origin 8.0 and Higher .. Workbooks with multiple sheets were first introduced in Origin 8.0 | 
               
              
                | masterd | 
                Posted - 03/15/2010 : 11:26:14 PM  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 | 
               
              
                | rlewis | 
                Posted - 07/13/2009 : 1:29:50 PM  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 ...");
	}
 | 
               
             
           | 
         
       
       
     |