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
 Forum for Origin C
 How to duplicate SHEET ih the same BOOK in OriginC
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Alex-qwerty

Russia
Posts

Posted - 01/29/2010 :  08:02:03 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver.: OriginPro 8.0 SR6
Operating System: WinXP SP2

How can I do in OriginC the same action as can I do by context menu of worksheet name "Duplicate Without Data"?
I tried to use Worksheet.CreateCopy(), but it creates a new WorkBook instead a new WorkSheet in the same WorkBook.
I want to create a new Sheet with the same structure with new Name an
d without data.
Thanks.

rlewis

Canada
253 Posts

Posted - 02/01/2010 :  11:12:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Probably not the most effecient way of doing it ... but it seems to work ..

	int WksDuplicate(Worksheet Wks, WorksheetPage &WPuser=NULL)
	{
	/*
		Create a duplicate of the  WorkSheet Wks as as a new sheet within the Parent Workbook Object  ... (WPuser=NULL)
		or the User-supplied Workbook Object "WPuser!=NULL"
		Returns the index of the newly created Worksheet
	*/		
		if(Wks.IsValid()==true)
		{
			WorksheetPage wpDest;
			if(WPuser==NULL)
			{
				wpDest=Wks.GetPage();
			}
			else
			{
				wpDest=WPuser;
			}
			if(wpDest.IsValid()==true)
			{
				return (wpDest.AddLayer(Wks));
			}
		}
		return (-1);
	}
	
	bool WksClear(Worksheet Wks, int Reduce=1, int SetAsBlank=1, int WarnMsg=0)
	{
	/*
		Clears the Data from the Worksheet Wks
		For info on the other parameters see the xFunction "wclear"
	*/		
	if(Wks.IsValid()==true)
	{
		string strXFname="wclear";
		XFBase xfwclear(strXFname);
		if(xfwclear)
		{
			if(xfwclear.SetArg("w",Wks)==true && xfwclear.SetArg("reduce",Reduce)==true && xfwclear.SetArg("op",SetAsBlank)==true && xfwclear.SetArg("msg",WarnMsg)==true)
            {
            	if(xfwclear.Evaluate()==true)
				{
					foreach (Column Col in Wks.Columns)
					{
						Col.SetLongName("");
					}
					return (true);
				}
            }
		}
	}
	return (false);
}

	void CreateNewSheet()
	{
		/*
			Creates a new sheet within the same workbook using he current worksheet as a template ...
		*/
		Worksheet Wks(Project.ActiveLayer());
		if(Wks.IsValid()==true)
		{
			int iLayr=WksDuplicate(Wks);
			if(iLayr>=0)
			{
				WorksheetPage Wpg=Wks.GetPage();
				if(Wpg.IsValid()==true)
				{
					Worksheet Wks1(Wpg.Layers(iLayr));
					WksClear(Wks1);
				}
			}
		}
	}
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